I need to get the Childwindow value to UserControl in silverlight Application. I tried the below way , I get null value in Usercontrol page.
ChildWindow
public partial class QE : ChildWindow
{
ATest ae= new ATest();
public void OKButton_Click(object sender, RoutedEventArgs e)
{
ae.Q = "TestValue";
this.DialogResult = true;
}
}
Class
public partial class ATest : UserControl
{
public string Q { get; set; }
public void asdf()
{
string checkvalue = Q.ToString();
}
}
I need to get the Child window's "TestValue" in UserControl page's checkvalue variable?How can I do this?
Get the value From childwindow to Usercontrol Page,Do the Following way,
Using public property in App.xaml
It acts as declaring a static global variable in "App.xaml.cs" and using it from any part of the application.
Declare a public property in "App.xaml.cs"
public string MyName { get; set; }
Now we can access this "MyName" property from anywhere in the application using the "App.Current" object.
Code to set MyName value in Page1.xaml
private void btnGo_Click(object sender, RoutedEventArgs e)
{
var obj = App.Current as App;
obj.MyName = "dpkshr";
this.NavigationService.Navigate(new Uri("/frmMap.xaml", UriKind.Relative));
}
Code to get MyName value in Page2.xaml
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
var obj = App.Current as App;
MessageBox.Show(obj.MyName);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.