开发者

EventTrigger RoutedEvent in wpf xaml

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 wro开发者_如何学Pythonng?


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜