There are a bunch of ways to do this, for example, you can cross VisualTree by clicking on the button of the parent element and extract the TextBox with the desired name. In this case, I would use the extension method written by yasen in this answer .
Then it might look like this:
private void Button_Click_1(object sender, RoutedEventArgs e)
{
var parent = (sender as Button).Parent;
TextBox firstOne = parent.GetChildrenOfType<TextBox>().First(x => x.Name == "firstBox");
Debug.WriteLine(firstOne.Text);
}
Remember to put the extension method somewhere in the static class:
public static class Extensions
{
public static IEnumerable<T> GetChildrenOfType<T>(this DependencyObject start) where T : class
{
source
share