asp教程.net 窗口之间值、控件的传递值
一、值的传递,很简单,因为在同一名称空间下,所以只需在要提供值的窗口里将值声明为public后,就可以在要引用值的窗口里通过“类名.变量名”使用了。如:
mainwindow.cs里:
public string test;
private void button2_click(object sender, routedeventargs e)
{
mytest test = new mytest();
test.showdialog();
}
在mytest.cs里:
public mytest()
{
initializecomponent();
mainwindow mw= new mainwindow();
this.content = mw.test;
}
二、控件的传递,和值传递类似,但需要更改子窗口的构造函数,在主窗口初始化时传递控件,如,我们现在传一个datagrid控件,并攻取它选中的值。
在mytest.cs里:
public mytest(datagrid mydg)
{
dg = mydg;
initializecomponent();
albums alb=new albums();
alb=dg.items[dg.selectedindex] as albums;
this.content = alb.title;
}
mainwindow.cs里:
private void button2_click(object sender, routedeventargs e)
{
mytest test = new mytest(datagrid1);
test.showdialog();
}