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

标签 .net wpf xaml

我的要求是我想在单击 button1 时在 button2 上设置闪烁效果。
我确实引用了这个例子来了解文本块上的闪烁效果。

Blinking TextBlock ?

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

最佳答案

尝试这个:

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

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


Blinking button on WPF application

关于.net - 在 XAML 中设置按钮的闪烁效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9257091/

相关文章:

wpf 文本框文字环绕

c# - WPF 中基于列名称及其值的 DataTriggers

WPF 覆盖 ContextMenu 样式 - DropShadowEffect 不起作用

c# - WPF 选项卡顺序工作错误

c# - 在 Repository<T> 中返回 Queryable<T> 或 List<T>

.net - 无法将 NuGet 包添加到 Monodevelop 5 中的引用

.net - 为 Linq 分组选择特定列

c# - 将 Dictionary<string, class> 转换为 IDictionary<string, interface>

wpf - 在扩展器上禁用 TabStop

c# - 将文本框值与其他控件中的值绑定(bind)