Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF blink an ellipse fill animation

Tags:

wpf

I was looking at this excellent post: How do I make an ellipse blink? Is there a way to not have the blink fade and instead just change the color immediately with no fade?

like image 596
tim Avatar asked Jul 03 '12 17:07

tim


1 Answers

Use DiscreteColorKeyFrame. Set the KeyTime to specify when you want it to trigger.

Here is an example of a blinking Ellipse. Fill alternates between Red and Blue every second

<Ellipse Fill="Red">
    <Ellipse.Triggers>
        <EventTrigger RoutedEvent="Ellipse.Loaded">
            <EventTrigger.Actions>
                <BeginStoryboard>
                    <Storyboard>
                        <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Ellipse.Fill).(SolidColorBrush.Color)"
                                                      Duration="0:0:2"
                                                      FillBehavior="HoldEnd"
                                                      RepeatBehavior="Forever">
                            <ColorAnimationUsingKeyFrames.KeyFrames>
                                <DiscreteColorKeyFrame KeyTime="0:0:0" Value="Red"/>
                                <DiscreteColorKeyFrame KeyTime="0:0:1" Value="Blue"/>
                            </ColorAnimationUsingKeyFrames.KeyFrames>
                        </ColorAnimationUsingKeyFrames>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger.Actions>                    
        </EventTrigger>
    </Ellipse.Triggers>
</Ellipse>
like image 115
Fredrik Hedblad Avatar answered Oct 17 '22 07:10

Fredrik Hedblad