views:

21

answers:

1

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.

A: 

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

Marko