2011-03-04 53 views
1

我試圖旋轉TextBlock 360度,只要它是綁定更新。如何使WPF TextBlock在其值更新時旋轉?

從我讀過的所有東西都應該可以工作,但是它沒有任何效果。我究竟做錯了什麼?

<TextBlock VerticalAlignment="Center" Text="{Binding Total, NotifyOnTargetUpdated=True}"> 

    <TextBlock.RenderTransform> 
     <RotateTransform x:Name="TotalSpinTransform" Angle="0"/> 
    </TextBlock.RenderTransform> 

    <TextBlock.Triggers> 
     <EventTrigger RoutedEvent="Binding.TargetUpdated"> 
      <EventTrigger.EnterActions> 
       <BeginStoryboard> 
        <Storyboard> 
         <DoubleAnimation Storyboard.TargetProperty="(TextBlock.RenderTransform).(RotateTransform.Angle)" 
          From="0" To="360" Duration="0:0:0.2" AutoReverse="True"/> 
        </Storyboard> 
       </BeginStoryboard> 
      </EventTrigger.EnterActions> 
     </EventTrigger> 
    </TextBlock.Triggers> 

</TextBlock>  
+0

你在運行時在輸出窗口中看到警告嗎? – RQDQ 2011-03-04 18:05:59

回答

4

無論EnterActions也不ExitActions適用於EventTrigger。不幸的是,這些屬性在TriggerBase上定義,因此它們出現在EventTrigger上。試試這個:

<EventTrigger RoutedEvent="Binding.TargetUpdated"> 
      <BeginStoryboard> 
       <Storyboard> 
        <DoubleAnimation Storyboard.TargetProperty="(TextBlock.RenderTransform).(RotateTransform.Angle)" 
         From="0" To="360" Duration="0:0:0.2" AutoReverse="True"/> 
       </Storyboard> 
      </BeginStoryboard> 
    </EventTrigger> 
+0

哈...我甚至沒有注意到它是EnterAction ...我只是假設Action(這是我在解決方案中的),並且將它放入樣式中來模擬樣本。雖然好的電話! – Scott 2011-03-04 20:30:24

+0

非常感謝您的幫助! – chillitom 2011-03-05 12:37:32