title: How to get TextBlock's Text value out of a StackPanel inside a Button in WPF
body: <p>I want to know how to get the text value out of a TextBlock that's inside a StackPanel that's inside a button in WPF, it goes pretty much like this:</p>
  
  <pre><code>public MainWindow()
  {
      Image img = new Image();
      img.Source = new BitmapImage(new Uri("image.png"));
  
      StackPanel stackPnl = new StackPanel();
      stackPnl.Orientation = Orientation.Vertical;
      stackPnl.Margin = new Thickness(10);
      stackPnl.Children.Add(img);
  
      TextBlock txtBlck = new TextBlock();
      txtBlck.Text = "this is a test!";
      stackPnl.Children.Add(txtBlck);
  
      Button btn = new Button();
      btn.Content = stackPnl;
      btn.Click += test_click;
      myPanel.Children.Add(btn);
  }
  </code></pre>
  
  <p>And test_click:</p>
  
  <pre><code>private void test_click(object sender, RoutedEventArgs e)
  {
      txtBox.Text = (sender as Button).Content.ToString();
  }
  </code></pre>
  
  <p>Now of course what I get after I click on the button is this <code>System.Windows.Controls.StackPanel</code>, which I guess it's pretty obvious since the StackPanel is the actual content of the button, but like I said, I need to know how to get only the Text value of the TextBlock, so in that case txtBox should display <code>this is a test!</code>. How can this be done?, and thanks in advance!</p>