views:

22

answers:

1

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

How can I expose the click event of the button inside such that I can assign different events for each instance of my UserControl.

I think this is similar to concept behind exposing DependencyProperty but I don't understand how to do it for events.

Thanks.

A: 

I normally add an event of the same name (and same parameters) to the user control and subscribe to the child control's original event, so I can pass the event on:

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 interested if there is a more general way of doing it.

Enough already