Https://www.cnblogs.com/fdyang/archive/2013/03/25/2980451.html
There are several ways:
1. Declare a global variable, that is, App.xaml inside the declaration, in all forms can be referenced application.current.properties["ArgumentName"];
2. The second is to expose a property on the target form, directly assigning a value;
3. Finally, the parameter navigationservice.navigate (window object,argument value) is passed inside the URI.
4. Use event response to pass the value.
For example: Click on a Opensubwindow button on the main window MainWindow-> Open the child window Subwindow-> Enter the value in the TextBox in the child window, click OK and then close the-> The textbox on the main window gets the value in the child window.
1. Define an event passvaluesevent in the child window. When the OK button is clicked, the event is triggered and the value is passed. (Passvalueseventargs is a EventArgs class that needs to be defined at the same time.)
public partial class Subwindow:window
{public
delegate void Passvalueshandler (object sender, Passvalueseventargs e);
public event Passvalueshandler Passvaluesevent;
Public Subwindow ()
{
InitializeComponent ();
}
private void Btnok_click (object sender, RoutedEventArgs e)
{
string value1 = Tbvalue1.text; The Text property return value is String type.
int value2;
Int32.TryParse (Tbvalue2.text, out value2);
Passvalueseventargs args = new Passvalueseventargs (value1, value2);
Passvaluesevent (this, args);
This. Close ();
}
}
2. In the main window of the Opensubwindow button click Method, subscribed to the Passvaluesevent event. Gets the value of the passed parameter when the event is triggered.
public partial class Mainwindow:window
{public
MainWindow ()
{
InitializeComponent ();
}
private void Btnopensubwindow_click (object sender, RoutedEventArgs e)
{
Subwindow subwindow = new Subwindow (); c9/>//Subscription Event
Subwindow.passvaluesevent + + new Subwindow.passvalueshandler (receivevalues);
Subwindow.show ();
}
private void Receivevalues (object sender, Passvalueseventargs e)
{
this.tbValue1.Text = e.value1;
This.tbValue2.Text = E.value2.tostring ();
}
}