简体   繁体   English

c#wpf为饼图旋转动画(使用PathGeometry绘制)

[英]c# wpf rotate animation for pie slice (drawn using PathGeometry)

Is there anyway for me to have a rotate animation for a PathGeometry that consists of arc and line segments (a pie) from angle A to angle B? 无论如何,我有没有为PathGeometry制作一个旋转动画,该动画包含从角度A到角度B的弧段和线段(扇形)?

The PathGeometry is drawn using c# instead of xaml, so answers in c# instead of xaml will be appreciated and the animation is required to be played when it's loaded. PathGeometry是使用c#而不是xaml绘制的,因此将赞赏使用c#而不是xaml的答案,并且需要在加载动画时播放动画。

Not sure if I'm missing something: can't you just apply RotateTransform to Transform , and then animate the Angle property? 不知道我是否缺少某些东西:您能否仅将RotateTransform应用于Transform ,然后为Angle属性设置动画? Eg: 例如:

<Path Stroke="Black" StrokeThickness="5" Width="100" Height="100">
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="RotationStates">
            <VisualState x:Name="RotatingState">
                <Storyboard Duration="0:0:1" RepeatBehavior="Forever" AutoReverse="True">
                    <DoubleAnimation Storyboard.TargetName="rotateTransform"
                                     Storyboard.TargetProperty="Angle"
                                     To="45"
                                     />
                </Storyboard>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Loaded">
            <ei:GoToStateAction StateName="RotatingState" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
    <Path.Data>
        <PathGeometry>
            <PathGeometry.Transform>
                <RotateTransform x:Name="rotateTransform" Angle="0" />
            </PathGeometry.Transform>
            <PathFigure StartPoint="10,10">
                <LineSegment Point="50,0" />
            </PathFigure>
        </PathGeometry>
    </Path.Data>
</Path>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM