Tutorial :Passing data from WPF tabs to a function



Question:

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.


Solution:1

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.../  }  


Solution:2

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


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »