我有一个WPF问题,一直无法解决。我在Stack Overflow上尝试了很多帖子,但都没有成功,所以想看看是否有人能帮忙。我只想让我的DataGrid单元格背景,根据值的上升或下降而脉动两种颜色之一。我尝试使用EventTrigger NotifyOnTargetUpdated,并绑定背景颜色,但是你不允许在storyboard中绑定属性背景。然后我尝试使用DataTriggers与状态字段“U”(表示上升)和“D”(表示下降)。我在每个更新周期(更新限制)的开始重置状态为“N”,最初使用两个DataTriggers来处理每种情况,看起来好像一切正常。我看到了绿色和红色的动画,但后来发现有一些更新没有被执行。一旦更新过来,似乎只有第一个声明的DataTrigger才会起作用,在极少数情况下,如果第一个条件没有出现,则另一个触发器会触发。 为了测试这个理论是否正确,我分别运行每个条件,如预期的那样,在每种情况下,第一个声明的触发器只会有90%的时间触发。我已经到处寻找原因,但没有找到,如果有人能够解决这个问题,或者甚至以更可靠的方式实现相同的功能,我将非常感激。
<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