属性更改触发的动画似乎没有触发

时间:2018-11-25 23:15:28

标签: wpf xaml

我正在尝试制作一个状态文本块,该文本块将显示诸如“数据库已更新”之类的内容以及其他对话框可能会过大的信息。它应该在屏幕上闪烁,然后在2秒钟左右消失。目标是将其透明度设为0,直到其绑定更新,然后设为1透明度并逐渐消失。问题是,我的想法似乎根本没有触发。这是我的代码:

<TextBlock Text="{Binding AppState.Feedback}" x:Name="feedbackBlock"
                 Opacity="0" FontSize="100" Foreground="Black">
    <TextBlock.Triggers>
        <EventTrigger RoutedEvent="Binding.TargetUpdated">
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation Storyboard.TargetName="feedbackBlock"
                             Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:2" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </TextBlock.Triggers>
</TextBlock>

不太确定该从哪里开始调试,我没有收到错误,只是没有显示。

1 个答案:

答案 0 :(得分:1)

您尚未告诉Binding触发TargetUpdated事件。将NotifyOnTargetUpdated=True添加到Binding表达式中。除此之外,您无需设置Storyboard.TargetName

<TextBlock x:Name="feedbackBlock"
           Text="{Binding AppState.Feedback, NotifyOnTargetUpdated=True}"
           Opacity="0" FontSize="100" Foreground="Black">
    <TextBlock.Triggers>
        <EventTrigger RoutedEvent="Binding.TargetUpdated">
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation Storyboard.TargetProperty="Opacity"
                                     To="1" Duration="0:0:2" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </TextBlock.Triggers>
</TextBlock>
相关问题