开发者

Is it possible to animate a LinearGradientBrush in WPF?

开发者 https://www.devze.com 2023-01-15 06:51 出处:网络
Is it possible to animate the StartPoint or EndPoint of a LinearGradientBrush? If so, what is the type of the Storyboard object used to animate the Points, as when I try the following I get \"0,1\" is

Is it possible to animate the StartPoint or EndPoint of a LinearGradientBrush? If so, what is the type of the Storyboard object used to animate the Points, as when I try the following I get "0,1" is not a valid value for Double, and I do realize I shouldn't be using the DoubleAnimationUsingKeyFrames type.

Current Code:

<UserControl.Triggers>
    <EventTrigger RoutedEvent="UserControl.Loaded">
        <BeginStoryboard>
            <Storyboard>
                <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" 
                                           Storyboard.TargetName="Path1" 
                                           Storyboard.TargetProperty="(Path.Stroke).(LinearGradien开发者_如何学GotBrush.StartPoint)">
                    <SplineDoubleKeyFrame KeyTime="00:00:0" Value="0,1"/>
                    <SplineDoubleKeyFrame KeyTime="00:00:2" Value=".5,.5"/>
                    <SplineDoubleKeyFrame KeyTime="00:00:4" Value="1,0"/>
                    <SplineDoubleKeyFrame KeyTime="00:00:6" Value=".5,.5"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" 
                                           Storyboard.TargetName="Path1" 
                                           Storyboard.TargetProperty="(Path.Stroke).(LinearGradientBrush.EndPoint)">
                    <SplineDoubleKeyFrame KeyTime="00:00:0" Value="1,0"/>
                    <SplineDoubleKeyFrame KeyTime="00:00:2" Value=".5,.5"/>
                    <SplineDoubleKeyFrame KeyTime="00:00:4" Value="0,1"/>
                    <SplineDoubleKeyFrame KeyTime="00:00:6" Value=".5,.5"/>
                </DoubleAnimationUsingKeyFrames>
            </Storyboard>
        </BeginStoryboard>
    </EventTrigger>
</UserControl.Triggers>


Yes. Just use "PointAnimationUsingKeyFrames" and "SplinePointKeyFrame" in your example above. It should work.

0

精彩评论

暂无评论...
验证码 换一张
取 消