I have the following DataGrid cell, which I would like to animate its background colour briefly as soon as the underlying LastTradePrice
property changes its value.
<DataGridTextColumn Header="Last Trade Price" Binding="{Binding LastTradePrice}">
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Style.Triggers>
// ???
<DataTrigger Binding="{Binding LastTradePrice}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<ColorAnimation To="Aqua" Duration="0:0:0.3" Storyboard.TargetProperty="Background.(SolidColorBrush.Color)"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
1) The line <DataTrigger Binding="{Binding LastTradePrice}" Value="True">
makes no sense though.
The property LastTradePrice
is obviously not a boolean to be measured with value = True
. How can I make the trigger to fire whenever the property is updated? Obviously I have INotification implemented:
public double LastTradePrice
{
get { return _model.LastTradePrice; }
set
{
if (value != _model.LastTradePrice)
{
LastTradePrice = value;
OnPropertyChanged("LastTradePrice");
}
}
}
2) If I would have stored the whole style definition inside <Window.Resources>
, how would I have accessed the ViewModels property LastTradePrice
?
Many Thanks
Binding.TargetUpdated
event. I've tested it and it works but it also triggers animation for initial value binding. – DelectationEventTrigger
and no code change in ViewModel is required. If you like you could extend this as an answer or I can do it too. :) – Bursar