是否可以在 WPF 中为 LinearGradientBrush 制作动画?

发布于 2024-09-18 10:37:09 字数 1788 浏览 4 评论 0原文

是否可以对 LinearGradientBrush 的 StartPoint 或 EndPoint 进行动画处理?如果是这样,用于对点进行动画处理的 Storyboard 对象的类型是什么,因为当我尝试以下操作时,我得到的“0,1”不是 Double 的有效值,而且我确实意识到我不应该使用 DoubleAnimationUsingKeyFrames类型。

当前代码:

<UserControl.Triggers>
    <EventTrigger RoutedEvent="UserControl.Loaded">
        <BeginStoryboard>
            <Storyboard>
                <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" 
                                           Storyboard.TargetName="Path1" 
                                           Storyboard.TargetProperty="(Path.Stroke).(LinearGradientBrush.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>

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).(LinearGradientBrush.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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

成熟稳重的好男人 2024-09-25 10:37:09

是的。只需在上面的示例中使用“PointAnimationUsingKeyFrames”和“SplinePointKeyFrame”即可。它应该有效。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文