如何使 WPF TextBlock 在其值更新时旋转?
每当绑定更新时,我都会尝试将 TextBlock 旋转 360 度。
从我读过的所有内容来看,以下内容应该有效,但没有任何效果。我做错了什么?
<TextBlock VerticalAlignment="Center" Text="{Binding Total, NotifyOnTargetUpdated=True}">
<TextBlock.RenderTransform>
<RotateTransform x:Name="TotalSpinTransform" Angle="0"/>
</TextBlock.RenderTransform>
<TextBlock.Triggers>
<EventTrigger RoutedEvent="Binding.TargetUpdated">
<EventTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="(TextBlock.RenderTransform).(RotateTransform.Angle)"
From="0" To="360" Duration="0:0:0.2" AutoReverse="True"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.EnterActions>
</EventTrigger>
</TextBlock.Triggers>
</TextBlock>
I'm trying to spin a TextBlock 360 degrees whenever it's binding updates.
From everything I've read the following should work, however it doesn't have any effect. What am I doing wrong?
<TextBlock VerticalAlignment="Center" Text="{Binding Total, NotifyOnTargetUpdated=True}">
<TextBlock.RenderTransform>
<RotateTransform x:Name="TotalSpinTransform" Angle="0"/>
</TextBlock.RenderTransform>
<TextBlock.Triggers>
<EventTrigger RoutedEvent="Binding.TargetUpdated">
<EventTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="(TextBlock.RenderTransform).(RotateTransform.Angle)"
From="0" To="360" Duration="0:0:0.2" AutoReverse="True"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.EnterActions>
</EventTrigger>
</TextBlock.Triggers>
</TextBlock>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
EnterActions
和ExitActions
均不适用于EventTrigger
。不幸的是,这些属性是在TriggerBase
上定义的,因此它们出现在EventTrigger
上。试试这个:Neither
EnterActions
norExitActions
are applicable toEventTrigger
. Unfortunately, these properties are defined onTriggerBase
so they are present on anEventTrigger
. Try this: