views:

14

answers:

2

I have a user control that is loaded into the parent window, and I want to raise a parent event when a button on the user control is clicked. How can I communicate with the parent through my user control in WPF?

A: 

First way that comes to mind is to have your UserControl raise an event that the parent window is listening to. The parent can then raise the event you want.

Eric
A: 

You're looking for Routed Events.

The Click event on Button is a RoutedEvent, so if your UserControl has a button then you can handle that event in the window. Add an attribute ButtonBase.Click="Window_Click" to the Window in your XAML and a handler private void Window_Click(object sender, RoutedEventArgs e) in the code-behind, and it will get called when any button in the window is clicked.

Quartermeister