How to trigger an Animation when TextBlock’s Text is changed during a DataBinding
Last time I wanted to fade out a TextBlock’s Text when the text has been changed. Unfortunately there is no TextChanged Event, but here is the solution:
<TextBlock x:Name=”tbMessage” Text=”{Binding Path=StatusBarText, NotifyOnTargetUpdated=True}”>
<TextBlock.Triggers>
<EventTrigger RoutedEvent=”Binding.TargetUpdated”>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty=”Opacity” Duration=”0:0:0″
To=”1.0″ />
<DoubleAnimation Storyboard.TargetProperty=”Opacity” Duration=”0:0:2″
From=”1.0″ To=”0.0″ BeginTime=”0:0:5″ />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</TextBlock.Triggers>
</TextBlock>
tnx! Saved me a bit of time 🙂
from here : http://stackoverflow.com/questions/1165862/animate-wpf-text-when-binding-updates-how
nice to hear of that…but there’s one lil’ mistake: the opacity should be set to 1.0 immediately after setting a new value for the textblock.
Thanks!! That was very useful.
Thanks. You’ve no idea how long I was looking for a way to do this. I can’t believe how hard it is to find a concise explanation for certain things in WPF.
thanks a lot