Open Button Click Event Inside UserControl in Silverlight

I have a button inside my UserControl. I have three instances of this UserControl on the same page.

How can I open a button click event inside so that I can assign different events for each instance of my UserControl.

I think this is similar to the concept of DependencyProperty disclosure, but I don't understand how to do this for events.

Thanks.

+4
source share
1 answer

Usually I add an event with the same name (and the same parameters) to the user control and subscribe to the original event of the child control, so I can pass the event to:

public partial class ClickEventControl : UserControl { public event EventHandler<RoutedEventArgs> Click; public ClickEventControl() { InitializeComponent(); } private void aButton_Click(object sender, RoutedEventArgs e) { if (Click != null) { Click(sender, e); } } } 

I would also be wondering if there is a more general way to do this.

+4
source

All Articles