[英]Get the Value from ChildWindow to UserControl Page
I need to get the Childwindow value to UserControl in silverlight Application. 我需要在Silverlight应用程序中将Childwindow值传递给UserControl。 I tried the below way , I get null value in Usercontrol page.
我尝试了下面的方法,我在Usercontrol页面中得到了空值。
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? 我需要在UserControl页面的checkvalue变量中获得Child窗口的“ TestValue”吗?该怎么办?
Get the value From childwindow to Usercontrol Page,Do the Following way, 获取从childwindow到Usercontrol Page的值,执行以下方法,
Using public property in App.xaml 在App.xaml中使用公共属性
It acts as declaring a static global variable in "App.xaml.cs" and using it from any part of the application. 它充当在“ App.xaml.cs”中声明静态全局变量并在应用程序的任何部分使用它的作用。
Declare a public property in "App.xaml.cs" 在“ App.xaml.cs”中声明一个公共属性
public string MyName { get; 公共字符串MyName {get; set;
组; }
}
Now we can access this "MyName" property from anywhere in the application using the "App.Current" object. 现在,我们可以使用“ App.Current”对象从应用程序中的任何位置访问此“ MyName”属性。
Code to set MyName value in Page1.xaml 在Page1.xaml中设置MyName值的代码
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 在Page2.xaml中获取MyName值的代码
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
var obj = App.Current as App;
MessageBox.Show(obj.MyName);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.