Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何围绕椭圆中心旋转弧段_C#_Wpf - Fatal编程技术网

C# 如何围绕椭圆中心旋转弧段

C# 如何围绕椭圆中心旋转弧段,c#,wpf,C#,Wpf,我有两种形状:一个椭圆和一个圆。我想绕着椭圆的中心旋转这个圆 <Path Stroke="Indigo" StrokeThickness="3" RenderTransformOrigin="0.5,0.5" Data="M 50 50 A 50 50 0 0 0 42.5 26.2"> <Path.RenderTransform> <RotateTransform Angle="270"/> <

我有两种形状:一个椭圆和一个圆。我想绕着椭圆的中心旋转这个圆

<Path Stroke="Indigo" StrokeThickness="3" RenderTransformOrigin="0.5,0.5"
      Data="M 50 50 A 50 50 0 0 0 42.5 26.2">
      <Path.RenderTransform>
           <RotateTransform Angle="270"/>
      </Path.RenderTransform>
</Path>
<Ellipse Stroke="Black" Width="50" Height="50"/>

这是我想要的


首先确保两个形状使用相同的坐标系。您可以在公共画布父对象中绘制两个路径,一个为
椭圆几何体
,另一个为
路径几何体
。画布的左上角定义了坐标原点

<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>
或者不明确命名旋转变换:

<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>


您的问题不清楚您是否真的想要设置圆弧段的动画,或者可能只是将其设置为“代码隐藏”中的某个值。你只是想要一个永远运行的动画吗?是的,我知道如何从代码隐藏中完成。谢谢!我正在尝试从xaml添加故事板。.有问题。哦,我可以用Data.Transform.Angle.Awsome!我明白了
<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>