[英]wpf button background change
I am trying to change the button color on click event.我正在尝试更改单击事件的按钮颜色。
This is my code:这是我的代码:
<Button Content="Start"
Command="{Binding DataContext.StartCounterCommand, ElementName=dgTemplate1}"
CommandParameter="{Binding SelectedItem, ElementName=dgTemplate1}" />
Use a style trigger on the pressed state, something like:在按下状态使用样式触发器,例如:
<Style x:Key="ButtonStyle" TargetType="{x:Type Button}">
<Style.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="Red" />
</Trigger>
</Style.Triggers>
</Style>
I dug up a good sample that is close here我挖到了一个很好的样本,离这里很近
If you are using MVVM them binding to a view model is also a good option as per @schlonzo如果您使用的是 MVVM,根据 @schlonzo,它们绑定到视图模型也是一个不错的选择
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.