我正在尝试制作一个状态文本块,该文本块将显示诸如“数据库已更新”之类的内容以及其他对话框可能会过大的信息。它应该在屏幕上闪烁,然后在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>
不太确定该从哪里开始调试,我没有收到错误,只是没有显示。
答案 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>