WPF怎么实现button按钮点击后背景变色再点击,背景色又变成默认的

2025-01-24 16:25:37
推荐回答(1个)
回答1:

我写了个例子给你,不肯定是不是你要实现的效果哈。(基于c#)
前端代码:






后台代码
public partial class Page1 : Page
{
public Page1()
{
InitializeComponent();
}

string tag=string.Empty;

private void btn_Click(object sender, RoutedEventArgs e)
{
Button btn = sender as Button;
if (tag == string.Empty)
{
btn.Background = new SolidColorBrush(Colors.Red);
txt.Text = "0";
tag = "0";
}
else
{
btn.Background = new SolidColorBrush(Colors.Blue);
txt.Text = "null";
tag = string.Empty;
}
}
}