tags:

views:

54

answers:

1

Hello,

in procedural code in can do the following:

// Add two event handler for the button click event
button1.Click += new RoutedEventHandler(button1_Click_1);
button1.Click += new RoutedEventHandler(button1_Click_2);

But how can I add multiple event handlers for the button's click event in XAML? Thanks for any hint!

+2  A: 

You cannot subscribe more than one event handler in XAML. You can however achieve the same effect by subscribing a single event handler and then calling two or more methods from the event handler.

    private void Button_OnClick(object sender, RoutedEventArgs e)
    {
        ButtonOnClick1();
        ButtonOnClick2();
    }

    private void ButtonOnClick1()
    {
        //Do something...
    }

    private void ButtonOnClick2()
    {
        //Do something...
    }
chibacity