I have some user controls. The hierarchy is as follows:
A contains B
B contains C
Inside my C control I have a button. When I click on it want my event
public event EventHandler Print;
to by raised and then I want control A to catch this event. How can I do this?
EDIT 1:
I want to raise my event on User Control C’s ViewModel
There are 2 topics that can help you fulfill your need:
Commanding
and
Routed Events
Both mechanisms are built specifically for wpf’s hierarchical structure.
Read up on both, they will help your wpf experience immeasurably.
EDIT: Something more helpful. Put Button.Click=”” on the control where you want to catch the event. You can use the button’s Tag property to store identifying information so your event handler knows that the correct button was clicked.
In your code behind for the user control you will require the handler named Button_ClickHandler.
The above method uses Router Events. I really recommend using Commands however.