Asp.net window value and control transfer value

Source: Internet
Author: User

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 ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.