I am trying to switch between two previously defined styles in App.xaml for multiple buttons each time a button gets clicked. I tried a generic event handler but it will display the error No overload for 'button_Click' matches delegate 'Windows.UI.Xaml.RoutedEventHandler'. I believe it has to do with the signature but can't quite fix it. Here's the method implemented in MainPage.xaml.cs
public void button_Click(object sender, EventArgs e)
    {
        var button = (Button)sender;
        if (button.Style != myButtonStyle)
            button.Style = myButtonStylePressed;
        else
            button.Style = myButtonStyle;
    }
And this is how it is implemented in MainPage.xaml in one button sample.
<Button Name="Row5Col4"
            Grid.Row ="5"
            Grid.Column ="4"
            Margin="10, 10, 10, 10"
            Height="10"
            Width="10" 
            HorizontalAlignment="Left"
            BorderThickness="0"
            Style="{StaticResource myButtonStyle}"
            Click="button_Click"
            >
    </Button>
IMPORTANT: some people have recommended using MouseClick instead of Click, however this won't work since it is a WP application. I appreciate you stopping by.
The line that, according to Visual Studio causes the bug is this one Click="button_Click"
Button's Click event doesn't have a parameter type of EventArgs.According to MSDN page , it has to be RoutedEventArgs
So your code must be :
public void button_Click(object sender, RoutedEventArgs e)
{
    var button = (Button)sender;
    if (button.Style != myButtonStyle)
        button.Style = myButtonStylePressed;
    else
        button.Style = myButtonStyle;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With