WPF闪烁椭圆填充动画

时间:2022-11-21 17:28:57

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?

我正在看这篇优秀的帖子:如何让椭圆闪烁?有没有办法没有眨眼褪色,而只是立即改变颜色,没有褪色?

1 个解决方案

#1


11  

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

使用DiscreteColorKeyFrame。设置KeyTime以指定您希望它何时触发。

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>

#1


11  

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

使用DiscreteColorKeyFrame。设置KeyTime以指定您希望它何时触发。

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>