<DataTemplate>
<StackPanel Name="stack" Background="PaleTurquoise">
<Grid>
<Slider Name="sld" Value="{Binding TimeLeft}" />
</Grid>
</StackPanel>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding ElementName=sld, Path=Value}" Value="0">
<DataTrigger.EnterActions>
<BeginStoryboard Name="flash">
<Storyboard TargetName="stack" Storyboard.TargetProperty="Background.(SolidColorBrush.Color)">
<ColorAnimation From="MediumSpringGreen" To="Crimson" Duration="0:0:0.1" AutoReverse="True" RepeatBehavior="0:0:5"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<RemoveStoryboard BeginStoryboardName="flash"/>
</DataTrigger.ExitActions>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
This is a cut down version of the xaml inside my alarm application. When the value of the slider hits 0 the ColorAnimation is triggered which animates the background of the StackPanel in which the Slider is contained.
However I want the Color of the Background to revert to the previous value (PaleTurquoise) when the flashing ends. How do I accomplish this in xaml?
As a further question, how can I get the DataTrigger to not fire when the application is first loaded even though TimeLeft in my ViewModel is 0 on initialization?
In the end I made a StaticResource for the default colour of the background and put another ColorAnimation after the first one thus:
<ColorAnimation To="{StaticResource alarmBackgroundColour}" BeginTime="0:0:5"/>
To answer the second part of getting the trigger to not fire on startup I hacked around it by making a ValueConverter return 1 for the first call only.
Any better solutions are welcome.