开发者

Expose a Click event of a button inside a UserControl in Silverlight

开发者 https://www.devze.com 2023-01-14 02:30 出处:网络
I have a button inside my UserControl. I have three instances of this Use开发者_JAVA百科rControl on the same page.

I have a button inside my UserControl. I have three instances of this Use开发者_JAVA百科rControl 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消