当 Textblocks 文本更新时触发动画 Text

发布于 2024-10-08 22:31:00 字数 952 浏览 0 评论 0原文

我有一个绑定到视图模型中的值的文本块。现在,当这个值更新时,我希望我的文本块淡入和淡出。 现在有这个方法

< 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只是在用心讲痛 2024-10-15 22:31:00

我这样做的方法是通过一个“视图服务”,例如由视图(页面或窗口)实现的 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文