Wpf xaml中的EventTrigger RoutedEvent

时间:2010-05-06 11:04:04

标签: wpf xaml events triggers

我在wpf xaml中遇到问题,我对此很新,所以它可能是基本的

我想360度旋转椭圆

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

但没有任何反应,出了什么问题?

1 个答案:

答案 0 :(得分:2)

首先。你将需要椭圆中的RotateTransform对象:

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

在故事板中更改这些属性:

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

它应该有效!

您也可以只更改TargetProperty,并将TargetName保留为t​​est:

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

这样,您的RotateTransform对象不需要名称!

全部放在一起:

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