CodingHero
CodingHero

Reputation: 3025

How do I set the Background after a Storyboard ColorAnimation complete in XAML?

How do I set the Background after a Storyboard ColorAnimation completes in XAML?

My ColorAnimation runs which makes Background flash red but after it returns to the original background colour (white) I would like it to remind red but i can't see how to do this.

My xaml is below - thanks

            <Grid Name="cell" Background="White">
                <Grid.Style>
                    <Style>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding DataItem.ControlValue, Converter={StaticResource IsNotNullOrEmptyConverter}}" Value="True">
                                <DataTrigger.EnterActions>
                                    <BeginStoryboard>
                                        <Storyboard x:Name="Blink" >
                                            <ColorAnimation Storyboard.TargetProperty="Background.Color" To="Red" 
                                                            RepeatBehavior="3x" Duration="0:0:1" AutoReverse="True"/>                                                    
                                        </Storyboard>
                                    </BeginStoryboard>   
                                </DataTrigger.EnterActions>
                                <DataTrigger.ExitActions>
                                    <RemoveStoryboard BeginStoryboardName="Blink" />
                                </DataTrigger.ExitActions>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Grid.Style>    

Upvotes: 1

Views: 1156

Answers (1)

Rohit Vats
Rohit Vats

Reputation: 81243

Set AutoReverse to False on your ColorAnimation if you don't want it to revert back to original value i.e White.

<ColorAnimation Storyboard.TargetProperty="Background.Color" To="Red" 
                RepeatBehavior="3x" Duration="0:0:1" AutoReverse="False"/> 

UPDATE

Add another ColorAnimation in your Storyboard which will begin after your first ColorAnimation completes may be after 4 sec interval.

<BeginStoryboard>
   <Storyboard x:Name="Blink">
     <ColorAnimation Storyboard.TargetProperty="Background.Color" To="Red" 
                     RepeatBehavior="3x" Duration="0:0:1" AutoReverse="True"/>
     <ColorAnimation Storyboard.TargetProperty="Background.Color" To="Red" 
                     Duration="0:0:1" BeginTime="0:0:4"/>
   </Storyboard>
</BeginStoryboard>

Upvotes: 2

Related Questions