WPF flashing ellipse fill animation

I watched this great post: How to make an ellipse blink? Is there a way to not fade away the blinking, but instead just change the color immediately without fading?

+5
source share
1 answer

Use DiscreteColorKeyFrame. Set KeyTimeto indicate when you want it to start.

Here is an example of blinking Ellipse. Fillalternating 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>
+11
source