在XAML中设置按钮的闪烁效果

dea*_*ace 4 .net wpf xaml

我的要求是我想在点击button1时在button2上设置闪烁效果.我确实引用了这个例子来对文本块进行闪烁效果.

闪烁TextBlock

但它不适用于我的button2.如果你愿意,我可以告诉你xaml代码.请帮助我.谢谢.

Sve*_*enG 9

试试这个:

  <Button Name="button1" Margin="10" Content="Animate Button2!">
    <Button.Triggers>
      <EventTrigger RoutedEvent="Button.Click">
        <EventTrigger.Actions>
          <BeginStoryboard>
            <Storyboard BeginTime="00:00:00" 
                                    RepeatBehavior="Forever" 
                                    Storyboard.TargetName="button2" 
                                    Storyboard.TargetProperty="(Foreground).(SolidColorBrush.Color)">
              <ColorAnimation From="Black" To="Red" Duration="0:0:1"/>
            </Storyboard>
          </BeginStoryboard>
        </EventTrigger.Actions>
      </EventTrigger>
    </Button.Triggers>
  </Button>

  <Button Name="button2" Margin="10" Content="I will get animated!"></Button>
Run Code Online (Sandbox Code Playgroud)

如果你想为背景设置动画:这并不容易实现,因为框架使用背景来处理内部事物,例如悬停动画.

请参阅 WPF应用程序上的闪烁按钮