请帮助将参数传递给父页面 [英] Please help passing parameter to parent page
本文介绍了请帮助将参数传递给父页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有子页面:
i have child page :
public partial class display1 : Page
{
private Page3 mdiParent;
public display1()
{
InitializeComponent();
}
public display1(Page3 m1_)
{
InitializeComponent();
this.mdiParent = m1_;
}
private void btnFin_Click(object sender, RoutedEventArgs e)
{
this.mdiParent.ChildMessage = "TEST"; // error here,Object reference not set to an instance of an object.
this.mdiParent.UpdateMessage();
}
}
i需要将参数传递给父页面:
i need to pass parameter to parent page here :
public partial class Page3 : Page
{
public Page3()
{
InitializeComponent();
}
private string childMessage;
public string ChildMessage
{
get { return childMessage; }
set { childMessage = value; }
}
private void btnDisplay_Click_1(object sender, RoutedEventArgs e)
{
framediag.Navigate(new display1());
}
public void UpdateMessage()
{
textBox1.Text = ChildMessage;
}
public void UpdateMessage(string message)
{
textBox1.Text = message;
}
请帮忙,明天我必须完成这项工作
please help, i have to done this work tomorrow
推荐答案
在您的子类中,您有以下两个构造函数:
In your child class you have the following two constructors:
public display1()
{
InitializeComponent();
}
public display1(Page3 m1_)
{
InitializeComponent();
this.mdiParent = m1_;
}
在您的父类中,您可以调用不带参数的那个:
In your parent class you call the one without parameters:
private void btnDisplay_Click_1(object sender, RoutedEventArgs e)
{
framediag.Navigate(new display1());
}
因此从未设置 mdiParent
变量,导致错误看到。您需要在构造函数的第二个版本中传递对父项的引用,例如:
So the mdiParent
variable is never set, leading to the error you see. You need to pass a reference to the parent in the second version of the constructor, something like:
private void btnDisplay_Click_1(object sender, RoutedEventArgs e)
{
framediag.Navigate(new display1(this));
}
谢谢Richard MacCutchan先生:)
Thank you Mr. Richard MacCutchan :)
这篇关于请帮助将参数传递给父页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文