简体   繁体   中英

apply a Style on the selected button

I have a list of 10 Buttons,in which I want to apply a specific Style when I select that Button,I did like that:

private bool button1WasClicked = false;
private bool button2WasClicked = false;
private bool button3WasClicked = false;
.....
private void button1_Click(object sender, EventArgs e)
{
    button1WasClicked = true;
}

private void button2_Click(object sender, EventArgs e)
{
    button2WasClicked = true;
}



private void Page_Loaded(object sender, RoutedEventArgs e)
        {
        if (button1WasClicked)
    { 
        apply the style on Button1
        button1WasClicked = false;
    }
       if (button2WasClicked)
    { 
        apply the style on Button2
        button2WasClicked = false;
    }
...... //complete the list of other buttons
        }

My question is,is there any other method I can use to apply the Style on the selected button of my 10 Buttons not the others

I hope someone can help me here.. thanks

这里有ToggleButton ,它带有Checked属性,并且对于Checked和Unchecked具有不同的VisualStates

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM