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>
</Te开发者_如何学编程xtBlock.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?
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
精彩评论