我有一个 WPF DataGrid,其行将闪烁红色以响应从服务器接收到的事件。这按预期工作,直到我添加浅灰色的交替颜色。行不再闪烁红色,而是闪烁浅灰色。
我知道有优先权,并发现了类似的帖子(WPF DataGrid AlternatingRowBackground 覆盖背景的 Style DataTrigger),但我正在使用动画。任何帮助将不胜感激。
<Style.Resources>
<Storyboard x:Key="FadeStoryboard" TargetProperty="Background.Color">
<DoubleAnimation Storyboard.TargetProperty="Opacity"
From=".5" To="1" Duration="0:0:0.5"
RepeatBehavior="Forever" AutoReverse="True"/>
</Storyboard>
</Style.Resources>
<!-- New event received from server ...alert operator by blinking red -->
<Style.Triggers>
<DataTrigger Binding="{Binding Acknowledged}" Value="False">
<Setter Property="Background" Value="red" />
<DataTrigger.EnterActions>
<BeginStoryboard x:Name="Blink" Storyboard="{StaticResource FadeStoryboard}"/>
</DataTrigger.EnterActions>
</DataTrigger>
<!-- Operator has acknowledged event; change background to normal -->
<DataTrigger Binding="{Binding Acknowledged}" Value="True">
<Setter Property="Background" Value="Transparent"/>
</DataTrigger>
</Style.Triggers>
我尝试在
我相信解决方案与您链接的帖子类似。然而,问题是你承认的将事情恢复正常的触发因素正在覆盖条带。
这对我有用:
<!-- Don't forget to add the alternation count property to the Grid -->
<DataGrid ItemsSource="{Binding Datas}" AlternationCount="2">
<DataGrid.Resources>
<Style TargetType="DataGridRow">
<Style.Resources>
<Storyboard x:Key="FadeStoryboard" TargetProperty="Background.Color">
<DoubleAnimation Storyboard.TargetProperty="Opacity" From=".5" To="1" Duration="0:0:0.5" RepeatBehavior="Forever" AutoReverse="True" />
</Storyboard>
</Style.Resources>
<!-- This handles the non-triggered/default color -->
<Setter Property="Background" Value="Transparent" />
<!-- New event received from server ...alert operator by blinking red -->
<Style.Triggers>
<Trigger Property="AlternationIndex" Value="1">
<Setter Property="Background" Value="Gray" />
</Trigger>
<DataTrigger Binding="{Binding Acknowledged}" Value="False">
<Setter Property="Background" Value="red" />
<DataTrigger.EnterActions>
<BeginStoryboard x:Name="Blink" Storyboard="{StaticResource FadeStoryboard}" />
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.Resources>
</DataGrid>