Reputation: 3
I have a WPF DataGrid whose rows will blink red in response to an event received from a server. This works as expected, until I add an alternating color of light gray. Instead of blinking red, the row(s) blink light gray.
I understand there is precedence and found this similar post (WPF DataGrid AlternatingRowBackground overriding the Style DataTrigger for background), but I'm using animation. Any help would be appreciated.
<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>
I've tried creating a trigger within <Style.Triggers>, but it was ignored.
Upvotes: 0
Views: 84
Reputation: 1248
I believe the solution is similar to the post you linked. However, the problem is that your acknowledged trigger that changes things back to normal is overriding the banding.
This got things working for me:
<!-- 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>
<!-- Suggested fix from the linked article -->
<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>
Upvotes: 0