假设我有一条折线,并且我希望只使用动画将折线的末端从 A 移动到 B。我该怎么做呢?
p/s:如果建议是针对折线而不是针对其他控件(例如路径等),我仍然会更喜欢:)
据我所知,开箱即用是不可能的,因为您试图Point
在PointCollection
. 您真正需要的是PointCollectionAnimation
WPF 不提供的 . 然而,了不起的 Charles Petzold 前段时间写了这篇文章,向您展示了如何去做。
由于接受的答案中提到的链接不再起作用,所以我发布了我的方法。
<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>