在 XAML 中设置按钮的闪烁效果 [英] To set blinking effect on button in XAML

查看:27
本文介绍了在 XAML 中设置按钮的闪烁效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的要求是我想在单击 button1 时在 button2 上设置闪烁效果.我确实参考了这个例子来了解 textblock 上的闪烁效果.

my requirement is I want to set blink effect on button2 when button1 is clicked. I did refer this example for blinking effect on textblock.

闪烁 TextBlock?

但它不适用于我的 button2.如果您愿意,我可以向您展示 xaml 代码.请帮帮我.谢谢.

but its not working for my button2. I can show you xaml code if you want. plz help me out. Thanks.

推荐答案

试试这个:

  <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>

如果您想为背景设置动画:这并不是那么容易实现,因为框架使用了内部内容的背景,例如悬停动画.

In case you want to animate the Background: This is not that easy to achieve as the framework is using the background for internal stuff, e.g. the hover animation.

WPF 应用程序上的闪烁按钮

这篇关于在 XAML 中设置按钮的闪烁效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆