简体   繁体   English

在所选按钮上应用样式

[英]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: 我有一个10个按钮的列表,当我选择那个按钮时,我想在其中应用特定的样式,我这样做是:

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 我的问题是,是否可以使用其他方法将样式应用到我的10个按钮的所选按钮上,而不是其他方法

I hope someone can help me here.. thanks 我希望有人可以在这里帮助我..谢谢

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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