[英]pass message from the parent window to child user control wpf
I have a window that is hosting a user control. 我有一个托管用户控件的窗口。 I wish to pass (raise) events in the parent window that should reach the user control.
我希望在父窗口中传递(引发)事件,这些事件应该到达用户控件。 How do I define events in the parent window that the child user control can also receive.
如何在子用户控件也可以接收的父窗口中定义事件。
As I recall the steps should be: 我记得这些步骤应该是:
Lets say in your window Loaded event attach the usercontrol to the event, eg - 假设在您的窗口Loaded事件中将usercontrol附加到事件,例如-
this.MyEvent += new this.MyDelegate(this.UserControl1.SomeMethod); this.MyEvent + =新this.MyDelegate(this.UserControl1.SomeMethod);
Take note that SomeMethod must match the MyDelegate definition. 请注意,SomeMethod必须与MyDelegate定义匹配。
For examples of how to define delegates/events then google is your friend ;) Also don't forget to unregister your usercontrol from the event, when it's no longer required (when the window closes). 有关如何定义委托人/事件的示例,那么google是您的朋友;)当不再需要事件时(窗口关闭时),请不要忘记从事件中注销用户控件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.