2013-10-08 44 views
1

我試圖在切換TabControl中的製表符的同時實現一個很好的動畫。
在這一點上,我的風格的動畫XAML看起來是這樣的:製作TabControl動畫

<EventTrigger RoutedEvent="SelectionChanged"> 
    <BeginStoryboard x:Name="selectionChangedBeginStoryboard"> 
     <Storyboard> 
      <DoubleAnimationUsingKeyFrames Storyboard.TargetName="borderScale" 
              Storyboard.TargetProperty="ScaleX"> 
       <DoubleKeyFrameCollection> 
        <EasingDoubleKeyFrame Value="0" KeyTime="0:0:0.2"/> 
        <EasingDoubleKeyFrame Value="1" KeyTime="0:0:0.4"/> 
       </DoubleKeyFrameCollection> 
      </DoubleAnimationUsingKeyFrames> 
     </Storyboard> 
    </BeginStoryboard> 
</EventTrigger> 

我想實現的是在標籤傳歷程旋轉的效果。所以它看起來像屏幕正在轉向,並返回新標籤頁。

問題是,當我切換到另一個標籤時, 馬上切換了內容,而動畫只是旋轉新標籤頁。

有什麼想法嗎? :)
謝謝!

回答

1

我建議您使用一個過渡庫,例如'Transitionals'。您可以從CodePlex上的Transitionals頁面下載此庫。

我之所以說這是因爲爲了做你想做的事,你會需要你切換標籤之前捕捉到的老TabItemVisual,動畫,代替TabItem然後刪除並恢復實際的控制。

但是,上述庫已經做到了這一點,並提供了許多不同的轉換供您使用。你可以得到幫助,通過下面的鏈接下載「TransitionalsHelp_1_0.zip」文件中使用庫:

http://transitionals.codeplex.com/releases/view/12954

1

而不是使用第三方程序,我建議混合。 在那裏打開你的解決方案並使用VisualStateManager。我在不到30秒內完成了從UnselectedSelected的過渡效果。這很簡單(不透明度改變),但Blend非常用戶友好,你可以本地與Visual Studio集成。

這裏就是它產生的是(不是你問):

   <Setter.Value> 
        <ControlTemplate TargetType="{x:Type TabItem}"> 
         <Grid x:Name="templateRoot" SnapsToDevicePixels="true"> 
          <VisualStateManager.VisualStateGroups> 
           <VisualStateGroup x:Name="CommonStates"/> 
           <VisualStateGroup x:Name="SelectionStates"> 
            <VisualStateGroup.Transitions> 
             <VisualTransition GeneratedDuration="0:0:0.3"/> 
            </VisualStateGroup.Transitions> 
            <VisualState x:Name="Unselected"> 
             <Storyboard> 
              <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="templateRoot"> 
               <EasingDoubleKeyFrame KeyTime="0" Value="0.8"/> 
              </DoubleAnimationUsingKeyFrames> 
             </Storyboard> 
            </VisualState> 
            <VisualState x:Name="Selected"/> 
           </VisualStateGroup> 
          </VisualStateManager.VisualStateGroups> 

好運。