1

我有以下 xaml 来显示旋转Ellipse

<Ellipse x:Name="ellipse"
         Stroke="{StaticResource _SpinnerGradientBrush}"
         StrokeThickness="20"                
         RenderTransformOrigin="0.5,0.5">
    <Ellipse.RenderTransform>
        <TransformGroup>
            <RotateTransform Angle="0" />
        </TransformGroup>
    </Ellipse.RenderTransform>
    <Ellipse.Triggers>
        <EventTrigger RoutedEvent="Ellipse.Loaded">
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimationUsingKeyFrames
                          Storyboard.TargetName="ellipse"
                          Storyboard.TargetProperty="(Ellipse.RenderTransform).(RotateTransform.Angle)"
                          Duration="0:0:4" 
                          RepeatBehavior="Forever">
                        <LinearDoubleKeyFrame Value="0" KeyTime="0:0:0" />
                        <LinearDoubleKeyFrame Value="359" KeyTime="0:0:4" />
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Ellipse.Triggers>
</Ellipse>

窗口将按预期显示,但动画永远不会开始。我已经在 Blend 中进行过这项工作,但由于某种原因,当我在我的应用程序中实际使用 xaml 时它不起作用。如果有人有任何想法,我将不胜感激。

4

1 回答 1

0

去掉 <TransformGroup> 标签,你只需要:

<Ellipse.RenderTransform>
    <RotateTransform Angle="0" />
</Ellipse.RenderTransform>

或者,为要设置动画的 RotateTransform 指定一个名称,并在动画中定位它(更改为 DoubleAnimation,因为它更短):

<Ellipse.RenderTransform>
    <TransformGroup>
        <RotateTransform Angle="0" x:Name="ellipseRotateTransform" />
    </TransformGroup>
</Ellipse.RenderTransform>
<Ellipse.Triggers>
    <EventTrigger RoutedEvent="Ellipse.Loaded">
        <BeginStoryboard>
            <Storyboard>
                <DoubleAnimation
                    Storyboard.TargetName="ellipseRotateTransform"
                    Storyboard.TargetProperty="Angle"
                    From="0" To="359"
                    Duration="0:0:4" 
                    RepeatBehavior="Forever">
                </DoubleAnimation>
            </Storyboard>
        </BeginStoryboard>
    </EventTrigger>
</Ellipse.Triggers>
于 2009-12-01T23:01:02.650 回答