This is a situation that comes up often:
In the View, you have a control bound to a ViewModel property (backed by a INotifyPropertyChanged). For example:
<TextBlock Text="{Binding Path=Subtotal}"/>
When the property changes, you need to bring the user attention to the fact with some creative animation. How I can utilize the fact that the view is already wired to the notification and avoid creating much of the extra code (or at least create it once and re-use). Data triggers are probably the best choice, but I do not know how to make them fire on any value change versus on some specific value.
The following options come to mind:
- raise an additional event in the ViewModel, subscribe in the View code-behind.
- create a datatrigger bound to the property mentioned using a convertor that would return true if the value is changing.
- create a datatrigger bound to a new boolean property on the ViewModel which is used to "signal" the change.
- create a behavior attached to the control which would subscribe to the control's dependency property change and start the animation.
Which one do you like/use? Did I miss any options?
P.S. It would be nice (but not critical) if the solution would provide a possibility to start the animation first and reflect the value change when it is ended.