C# 路径动画
我想让我的路径有动画。这是路径的示例代码:C# 路径动画,c#,animation,vector,path,uwp,C#,Animation,Vector,Path,Uwp,我想让我的路径有动画。这是路径的示例代码: <Path Stroke="BlueViolet" StrokeThickness="2"> <Path.Data> <PathGeometry> <PathGeometry.Figures> <PathFigure StartPoint="30, 80">
<Path Stroke="BlueViolet" StrokeThickness="2">
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigure StartPoint="30, 80">
<LineSegment Point="50, 80"/>
<QuadraticBezierSegment Point1="70, 20" Point2="90, 80" x:Name="qbs1"/>
<QuadraticBezierSegment Point1="110, 140" Point2="130, 80" x:Name="qbs2"/>
<LineSegment Point="150, 80"/>
</PathFigure>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>
我需要它来制作这样的动画:
<Storyboard x:Name="pointanimation">
<PointAnimation From="70,20"
To="70,140"
EnableDependentAnimation="True"
RepeatBehavior="Forever"
AutoReverse="True"
Storyboard.TargetName="qbs1"
Storyboard.TargetProperty="Point1"/>
<PointAnimation From="110, 140"
To="110, 20"
EnableDependentAnimation="True"
RepeatBehavior="Forever"
AutoReverse="True"
Storyboard.TargetName="qbs2"
Storyboard.TargetProperty="Point1"/>
</Storyboard>
我哪里出错了?我应该怎么做才能使它工作?您需要在每个
点动画上设置EnableDependentAnimation=“True”
,才能工作
因此,请按如下方式更改情节提要:
<Storyboard x:Name="pointanimation">
<PointAnimation From="70,20"
To="70,140"
EnableDependentAnimation="True"
RepeatBehavior="Forever"
AutoReverse="True"
Storyboard.TargetName="qbs1"
Storyboard.TargetProperty="Point1"/>
<PointAnimation From="110, 140"
To="110, 20"
EnableDependentAnimation="True"
RepeatBehavior="Forever"
AutoReverse="True"
Storyboard.TargetName="qbs2"
Storyboard.TargetProperty="Point1"/>
</Storyboard>
您需要设置此选项,因为这可能会影响性能。(
private void button_Click(object sender, RoutedEventArgs e)
{
pointanimation.Begin();
}
<Storyboard x:Name="pointanimation">
<PointAnimation From="70,20"
To="70,140"
EnableDependentAnimation="True"
RepeatBehavior="Forever"
AutoReverse="True"
Storyboard.TargetName="qbs1"
Storyboard.TargetProperty="Point1"/>
<PointAnimation From="110, 140"
To="110, 20"
EnableDependentAnimation="True"
RepeatBehavior="Forever"
AutoReverse="True"
Storyboard.TargetName="qbs2"
Storyboard.TargetProperty="Point1"/>
</Storyboard>