I have an issue with WPF I just cannot fix and I have been many stackoverflow posts without any luck so I thought I would see if anyone could help
I simply want the cell background of my DataGrid to pulse one of two colours depending on the value whether value goes up or down
I tried using EventTrigger NotifyOnTargetUpdated and binding the background colour but you are not allowed bind to property background in storyboard
I then tried using DataTriggers with a state field, "U" for up, "D" for down. I reset the state to "N" at the start of each update cycle (updates throttled) and at first, with 2 DataTriggers for each scenario , it looked like all is working fine. I was seeing both green & red animations but then I noticed that there were updates happening with no updates. Once updates came through, it seemed only the DataTrigger that was declared first would actually work, on the rare occasion when there is no occurrences of first condition, the other trigger would fire. To test this theory was true I ran with each condition first and as expected in each case the first declared trigger would only fire 90% the time.
I have searched everywhere to try find reason for this anomaly but have had no luck, if anyone can shed some light on how to fix this issue or even perhaps implement the same functionality in a more reliable way, would greatly appreciate it.
<DataGridTextColumn Header="Last Trade" Width="60" Binding="{Binding last_trade}" IsReadOnly="true">
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=last_trade_state}" Value="D">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="Background.Color" Duration="00:00:01" From="LightSalmon" To="Transparent"></ColorAnimation>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
<DataTrigger Binding="{Binding Path=last_trade_state}" Value="U">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetProperty="Background.Color" Duration="00:00:01" From="LightGreen" To="Transparent"></ColorAnimation>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGridTextColumn.CellStyle>
</DataGridTextColumn>
INotifyPropertyChanged
? – lokusking