views:

323

answers:

1

I have a problem in wpf xaml and i'm pretty new on this so it may be something basic

i want to rotate a ellipse 360 degree

<Ellipse Name="test" Fill="Black" StrokeThickness="5" Margin="0,0,0,0" Height="66">
        <Ellipse.Triggers>
            <EventTrigger RoutedEvent="Ellipse.Loaded" SourceName="test">
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation
                        Storyboard.TargetName="test"
                        Storyboard.TargetProperty="(Ellipse.RenderTransform).(RotateTransform.Angle)"
                        From="0"
                        To="360"
                        Duration="0:0:0.5"
                        RepeatBehavior="1x" />
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Ellipse.Triggers>
    </Ellipse>

But nothing happens, what is wrong?

+1  A: 

First of all. you will need the RotateTransform object in your ellipse:

<Ellipse.RenderTransform>
    <RotateTransform x:Name="transform" />
</Ellipse.RenderTransform>

Change these properties in your Storyboard:

Storyboard.TargetName="transform"
Storyboard.TargetProperty="Angle"

And it should work!

You can also only change the TargetProperty, and leave the TargetName on test:

Storyboard.TargetName="test"
Storyboard.TargetProperty="RenderTransform.Angle"

That way, your RotateTransform object does not need a name!

Putting it all together:

<Ellipse Name="test" Fill="Black" StrokeThickness="5" Margin="0,0,0,0" Height="66">
    <Ellipse.RenderTransform>
        <RotateTransform />
    </Ellipse.RenderTransform>
    <Ellipse.Triggers>
      <EventTrigger RoutedEvent="Ellipse.Loaded" SourceName="test">
        <BeginStoryboard>
        <Storyboard>
            <DoubleAnimation 
                Storyboard.TargetName="test"
                Storyboard.TargetProperty="RenderTransform.Angle"
                From="0" To="360" Duration="0:0:0.5" RepeatBehavior="1x" />
        </Storyboard>
        </BeginStoryboard>
      </EventTrigger>
    </Ellipse.Triggers>
</Ellipse>
Arcturus
Worked like a charm :) Thank you
Cinaird