【问题标题】:Fire xaml animation in style when bound property updated [duplicate]绑定属性更新时以样式触发 xaml 动画 [重复]
【发布时间】:2020-06-09 13:09:36
【问题描述】:

我有一个 wpf 应用程序,它绑定到代码隐藏中的属性。
由于标准的 OnPropertyChanged() 行为,它们会更新 - 到目前为止一切都很好。

每当该值更新时,我想短暂地闪烁 xaml 对象的背景 - 以提醒眼睛注意值的变化。我觉得这应该很容易,但我认为存在语法问题。

到目前为止,我已经尝试过闪现一个Label的背景:

<Style TargetType="{x:Type Label}">
    <Style.Triggers>
        <EventTrigger RoutedEvent="Binding.TargetUpdated">
            <BeginStoryboard>
                <Storyboard AutoReverse="True">
                    <ColorAnimation Duration="0:0:0.3" 
                                    Storyboard.TargetProperty="Background" 
                                    To="Blue"/>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Style.Triggers>
</Style>

..我做错了什么?

【问题讨论】:

标签: wpf xaml data-binding eventtrigger


【解决方案1】:

@Pavel 为我指明了正确的方向。

在我的 xaml 控件上,我需要将 NotifyOnTargetUpdated 添加到绑定中,如下所示:

Content="{Binding ID, NotifyOnTargetUpdated=True}"

【讨论】:

  • 您还必须定位 Storyboard.TargetProperty="Background.Color",因为 ColorAnimation 不能直接设置背景画笔。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-11
  • 1970-01-01
  • 2016-08-07
  • 2013-12-13
  • 1970-01-01
相关资源
最近更新 更多