首先确保两个形状使用相同的坐标系是什么。您可以在一个普通的Canvas父级中将两者绘制为Path
,其中一个具有EllipseGeometry
,另一个具有PathGeometry
。画布的左上角定义了坐标原点。
<Canvas Margin="100">
<Path Stroke="Black">
<Path.Data>
<EllipseGeometry RadiusX="50" RadiusY="50"/>
</Path.Data>
</Path>
<Path Stroke="LightBlue" StrokeThickness="5">
<Path.Data>
<PathGeometry>
<PathFigure StartPoint="0,-50">
<ArcSegment Point="42.5,-26.2" Size="50,50"
IsLargeArc="False" SweepDirection="Clockwise"/>
</PathFigure>
<PathGeometry.Transform>
<RotateTransform Angle="15"/>
</PathGeometry.Transform>
</PathGeometry>
</Path.Data>
</Path>
</Canvas>
现在ArcSegment的Point
和RotateTransform的Angle
根据自己的需要进行调整。
更新:可以添加一个不断旋转的弧段像这样的动画:
<Path Stroke="LightBlue" StrokeThickness="5">
<Path.Data>
<PathGeometry>
<PathFigure StartPoint="0,-50">
<ArcSegment Point="42.5,-26.2" Size="50,50"
IsLargeArc="False" SweepDirection="Clockwise"/>
</PathFigure>
<PathGeometry.Transform>
<RotateTransform x:Name="transform"/>
</PathGeometry.Transform>
</PathGeometry>
</Path.Data>
<Path.Triggers>
<EventTrigger RoutedEvent="Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="transform"
Storyboard.TargetProperty="Angle"
To="360" Duration="0:0:2" RepeatBehavior="Forever"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Path.Triggers>
</Path>
或者没有显式命名RotateTransform:
<Path Stroke="LightBlue" StrokeThickness="5">
<Path.Data>
<PathGeometry>
<PathFigure StartPoint="0,-50">
<ArcSegment Point="42.5,-26.2" Size="50,50"
IsLargeArc="False" SweepDirection="Clockwise"/>
</PathFigure>
<PathGeometry.Transform>
<RotateTransform/>
</PathGeometry.Transform>
</PathGeometry>
</Path.Data>
<Path.Triggers>
<EventTrigger RoutedEvent="Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetProperty="Data.Transform.Angle"
To="360" Duration="0:0:2" RepeatBehavior="Forever"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Path.Triggers>
</Path>
的感谢!我试图添加一个Storyboard。 – Jandy
从您的问题中不清楚您是否真的想要为弧段创建动画,或者可能只是将其设置为来自代码后面的某个值。你只是想要一个永远运行的动画? – Clemens
是的,我知道如何从代码背后做。谢谢!我试图从XAML添加一个故事板<故事板播放时间= “0:0:1” RepeatBehavior = “永久” 自动翻转= “真”> \t \t \t \t \t \t \t \t .Having a problem。 –
Jandy