将值从子窗口传回 MainPage [英] Pass value from child window back to MainPage

查看:27
本文介绍了将值从子窗口传回 MainPage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Silverlight 中有一个子窗口,我希望发送一个字符串值来填充应用程序 MainPage.xaml 中的文本框.

I have a child window in Silverlight and I wish to send a string value to populate a text box in the applications MainPage.xaml.

如何将值传回?

我已经试过了 -

MainPage m = (MainPage)Application.Current.RootVisual;
m.textBox1.Text = value;

推荐答案

你应该反过来做.打开子窗口的父窗口应该为子窗口的事件附加一个事件处理程序,例如:

You should do this the other way around. The parent that opens the child window should attach an event handler to an event of the child, for example:

 childwindow.ButtonClicked += new EventHandler(childWindow_ButtonClicked);

在此处理程序中,父级可以使用子窗口的属性值更新自己的控件.

Within this handler, the Parent can update its own Controls with values from properties of the child Window.

private void childWindow_ButtonClicked(object sender, EventArgs e)
      {
            txtValue.Text = childwindow.Value;
      }

这篇关于将值从子窗口传回 MainPage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆