如何使用 doubleanimation / pointanimation 对折线点进行动画处理

发布于 2024-12-12 18:00:11 字数 164 浏览 5 评论 0原文

假设我有一条折线,并且我希望使用动画仅将折线的末端从 A 移动到 B。我应该怎样去做呢?

p/s:如果建议是针对折线而不是针对路径等其他控件,我仍然会更喜欢:)

在此输入图像描述

Assuming I have a Polyline and I wish to move only the end of the Polyline from A to B using animation. How should I go about doing it?

p/s: I'll still prefer if the suggestion is for polyline and not for other controls such as path and so on :)

enter image description here

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

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

发布评论

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

评论(2

只为一人 2024-12-19 18:00:11

据我所知,不可能开箱即用,因为您正在尝试为 PointCollection 内的 Point 制作动画。您真正需要的是一个 PointCollectionAnimation,而 WPF 并未提供。然而,出色的 Charles Petzold 不久前写了这篇文章,向您展示了如何你可以去做。

Not possible out of the box as far as I'm aware, since you're trying to animate a Point within a PointCollection. What you really need is a PointCollectionAnimation, which WPF doesn't provide. However, the awesome Charles Petzold wrote this article some time ago showing you how you can go about it.

紫南 2024-12-19 18:00:11

由于已接受的答案中提到的链接不再有效,因此我发布了我的方法。

<Path Stroke="Red">
            <Path.Data>
                <GeometryGroup>
                    <LineGeometry x:Name="G1" StartPoint="100,100" EndPoint="100,0"/>
                </GeometryGroup>
            </Path.Data>
            <Path.Triggers>
                <EventTrigger RoutedEvent="Loaded">
                    <BeginStoryboard>
                        <Storyboard>                            
                            <PointAnimationUsingPath Storyboard.TargetName="G1" Storyboard.TargetProperty="EndPoint">
                                <PointAnimationUsingPath.PathGeometry>
                                    <PathGeometry Figures="M 100,0 C 150,50 200,75 250, 100" />
                                </PointAnimationUsingPath.PathGeometry>
                            </PointAnimationUsingPath>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Path.Triggers>
        </Path>

As the link mentioned in the accepted answer doesn't work anymore, so I am posting my approach.

<Path Stroke="Red">
            <Path.Data>
                <GeometryGroup>
                    <LineGeometry x:Name="G1" StartPoint="100,100" EndPoint="100,0"/>
                </GeometryGroup>
            </Path.Data>
            <Path.Triggers>
                <EventTrigger RoutedEvent="Loaded">
                    <BeginStoryboard>
                        <Storyboard>                            
                            <PointAnimationUsingPath Storyboard.TargetName="G1" Storyboard.TargetProperty="EndPoint">
                                <PointAnimationUsingPath.PathGeometry>
                                    <PathGeometry Figures="M 100,0 C 150,50 200,75 250, 100" />
                                </PointAnimationUsingPath.PathGeometry>
                            </PointAnimationUsingPath>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Path.Triggers>
        </Path>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文