2010-05-06 84 views
0

我在WPF XAML一個問題,我很新的這所以它可能是一些基本的東西EventTrigger RoutedEvent在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> 

但沒有發生了什麼事?

回答

2

首先。你將需要RotateTransform對象在橢圓:

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

更改這些屬性在你的故事板:

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

,它應該工作!

也只能更改TargetProperty,而假的TargetName上測試:

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

工作就像一個魅力:)謝謝 – Cinaird 2010-05-06 11:50:07