views:

59

answers:

2

I have a WPF app with a single form containing some WPF tabs. Three of the tabs are used to collect data from the user. The last tab has an OK button and when clicked performs some calculations.

How to I pass data from the text boxes on the various tabs to the function located in the buttonclick event? I have the function created. I just need to know how to reference the values from the textboxes on the tabs.

A: 

Give the controls a name with the Name="myTextBox" attribute then Visual Studio or Blend will create identifiers for the controls in the code-behind for your form and you can access them via their names.

void OKButton_Click(object sender, EventArgs e) {
   // string first = firstName.Text;
   // string last = lastName.Text;
   // etc.../
}
Josh Einstein
I thought that's the way it should work. After a reboot, my intellisense contained the textboxes and everything was fine.
Scott
If this worked for you, you make it your accepted answer.
Will Eddins
A: 

If your textboxes have Name or x:Name attributes set on them in XAML, you can access them in your codebehind.

statenjason