根据值的变化闪烁高亮一个按钮

Blink highlight a button according to its value changes

我有 WPF 控件,它有一个包含许多按钮的列表视图 我需要这些按钮在它们的绑定值发生变化时闪烁并突出显示一小段时间(当值上升时变为绿色,下降时变为红色)。

最好的方法是什么?

以下示例使用触发器在按钮的 IsMouseOver 属性 变为 Green 时为按钮的 Foreground 设置动画。

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      WindowTitle="Animate Properties with Storyboards">

  <Page.Resources>
    <Style x:Key="PropertyTriggerExampleButtonStyle" TargetType="{x:Type Button}">
      <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
          <Trigger.EnterActions>
            <BeginStoryboard>
              <Storyboard>
                <DoubleAnimation Storyboard.TargetProperty="Foreground" To="Green"  />
              </Storyboard>
            </BeginStoryboard>
          </Trigger.EnterActions>
          <Trigger.ExitActions>
        </Trigger>               
      </Style.Triggers>    
    </Style>
  </Page.Resources>

  <StackPanel Margin="20">  
    <Button Style="{StaticResource PropertyTriggerExampleButtonStyle}"  />
  </StackPanel>
</Page>

<Trigger Property="IsMouseOver" Value="True">修改为你想要的触发器,然后做你想要的动画。