简体   繁体   中英

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:

  1. Define a delegate in your parent window
  2. Define an event in your parent window
  3. Lets say in your window Loaded event attach the usercontrol to the event, eg -

    this.MyEvent += new this.MyDelegate(this.UserControl1.SomeMethod);

    Take note that SomeMethod must match the MyDelegate definition.

  4. Raise the event in your parent window per application logic.

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).

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM