我想要一个动画,适应窗口的大小。
我使用code example复制了点动画中的代码,并对其进行了一些修改。我添加了一条新的路径,这样我就可以看到圆圈所沿着的路径。我还为圆圈做了一条更简单的路径。
我可以将Stretch="Fill"添加到显示圆路径的路径中。现在,路径的大小随窗口大小而变化。如何对动画的路径执行此操作,并使其遵循与所示路径相同的路径?
<Window x:Class="TestPointAlongPath.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:PresentationOptions="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
mc:Ignorable="PresentationOptions"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Path Data="M1,200 L275,1 L345,200" Margin="15,15,15,15"
Stroke="#BF708090" StrokeThickness="3" />
<Path Fill="Blue" Margin="15,15,15,15" >
<Path.Data>
<!-- The EllipseGemetry specifies the shape and position of the Ellipse. The
Center property is animated, causing the Ellipse to animate across the screen-->
<EllipseGeometry x:Name="MyAnimatedEllipseGeometry"
Center="10,100" RadiusX="15" RadiusY="15"/>
</Path.Data>
<Path.Triggers>
<EventTrigger RoutedEvent="Path.Loaded">
<BeginStoryboard Name="MyBeginStoryboard">
<Storyboard>
<!-- Animates the ellipse along the path. -->
<PointAnimationUsingPath
Storyboard.TargetName="MyAnimatedEllipseGeometry"
Storyboard.TargetProperty="Center"
Duration="0:0:7.5"
RepeatBehavior="Forever" >
<PointAnimationUsingPath.PathGeometry>
<PathGeometry
Figures="M1,200 L275,1 L345,200"
PresentationOptions:Freeze="True">
<PathGeometry.Transform>
<ScaleTransform ScaleX="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType=Grid}}"
ScaleY="{Binding ActualHeight, RelativeSource={RelativeSource AncestorType=Grid}}"/>
</PathGeometry.Transform>
</PathGeometry>
</PointAnimationUsingPath.PathGeometry>
</PointAnimationUsingPath>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Path.Triggers>
</Path>
</Grid>
</Window>发布于 2017-04-06 01:28:15
您托管了Canvas下的路径。Canvas需要精确的位置。请改用栅格。所有的路径都将位于另一条路径之上。然后,您可以使用它们的Stretch属性来计算它们的拉伸。此外,您也不需要Page元素。
https://stackoverflow.com/questions/43229601
复制相似问题