Asp tutorial. net window value and control transfer value
1. Transfer of values is very simple. Because in the same namespace, you only need to declare the value as public in the window to provide the value, you can use the class name in the window to reference the value. the variable name is used. For example:
In mainwindow. cs:
Public string test;
Private void button2_click (object sender, routedeventargs e)
{
Mytest test = new mytest ();
Test. showdialog ();
}
In mytest. cs:
Public mytest ()
{
Initializecomponent ();
Mainwindow mw = new mainwindow ();
This. content = mw. test;
}
2. The transfer of controls and the transfer of values are similar, but you need to change the constructor of the subwindow to pass controls during the initialization of the main window. For example, we will now pass a datagrid control, and obtain the selected value.
In mytest. cs:
Public mytest (datagrid mydg)
{
Dg = mydg;
Initializecomponent ();
Albums alb = new albums ();
Alb = dg. items [dg. selectedindex] as albums;
This. content = alb. title;
}
In mainwindow. cs:
Private void button2_click (object sender, routedeventargs e)
{
Mytest test = new mytest (datagrid1 );
Test. showdialog ();
}