当 Textblocks 文本更新时触发动画 Text
我有一个绑定到视图模型中的值的文本块。现在,当这个值更新时,我希望我的文本块淡入和淡出。 现在有这个方法
< TextBlock ...>
<TextBlock.Triggers>
<EventTrigger RoutedEvent="TextBlock.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="VolumeTextBlock"
Storyboard.TargetProperty="Opacity"
From="1.0" To="0.0" Duration="0:0:1" AutoReverse="True"
RepeatBehavior="Forever"
/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</TextBlock.Triggers>
< /TextBlock>
,但这仅适用于鼠标悬停/鼠标输入/加载,而不是在文本更改时有效。谁能告诉我如何做到这一点?
I have a Textblock that is bound to a value in my viewmodel. Now when this value is updated I want my textblock to fade in and out.
Now there is this method
< TextBlock ...>
<TextBlock.Triggers>
<EventTrigger RoutedEvent="TextBlock.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="VolumeTextBlock"
Storyboard.TargetProperty="Opacity"
From="1.0" To="0.0" Duration="0:0:1" AutoReverse="True"
RepeatBehavior="Forever"
/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</TextBlock.Triggers>
< /TextBlock>
But this only works for mouseover/mouseentered/loaded and not when text is changed. Could anyone tell me how this can be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我这样做的方法是通过一个“视图服务”,例如由视图(页面或窗口)实现的 IAnimationService,并注入到 ViewModel 内。当属性更改时,VM 可以调用 MyAnimationService.StartMyAnimation() 等。
干杯,
洛朗
The way I do this is by having a "view service" for example IAnimationService that is implemented by the View (the Page or the Window), and injected inside the ViewModel. When the property changes, the VM can invoke MyAnimationService.StartMyAnimation() or something.
Cheers,
Laurent