2011-12-31 33 views
0

我正在顯示一個畫布,並希望當手機從縱向旋轉到橫向時,它會平滑地旋轉90度。在Windows Phone 7中平滑地將控件從縱向旋轉到縱向

看起來,當手機旋轉(至少在模擬器中)畫布會自動旋轉,但過渡不是光滑的(即它從0到90度) - 我認爲這是自動 - 佈局功能。

我希望我的畫布可以平滑地旋轉,即不會突然從0跳到90度(就像自動佈局功能一樣)。我在混紡狀態管理器設置兩種狀態,我調用如下

private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e) 
    { 
     if ((e.Orientation & PageOrientation.Landscape) != 0) 
     { 
      VisualStateManager.GoToState(this, "Landscape", true); 
     } 
     else 
     { 
      VisualStateManager.GoToState(this, "Portrait", true); 
     } 
    } 

我已經設置了這之間的過渡如下:

<VisualStateManager.VisualStateGroups> 
    <VisualStateGroup x:Name="OrientationStates"> 
     <VisualStateGroup.Transitions> 
      <VisualTransition From="Portrait" GeneratedDuration="0" To="Landscape"> 
       <Storyboard> 
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.Rotation)" Storyboard.TargetName="LayoutRoot"> 
         <EasingDoubleKeyFrame KeyTime="0" Value="90"/> 
         <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/> 
        </DoubleAnimationUsingKeyFrames> 
       </Storyboard> 
      </VisualTransition> 
      <VisualTransition From="Landscape" GeneratedDuration="0" To="Portrait"> 
             <Storyboard> 
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.Rotation)" Storyboard.TargetName="LayoutRoot"> 
         <EasingDoubleKeyFrame KeyTime="0" Value="90"/> 
         <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/> 
        </DoubleAnimationUsingKeyFrames> 
       </Storyboard> 
      </VisualTransition> 
     </VisualStateGroup.Transitions> 
     <VisualState x:Name="Portrait"/> 
     <VisualState x:Name="Landscape"/> 
    </VisualStateGroup> 
</VisualStateManager.VisualStateGroups> 

有趣的一點是,它似乎在過渡應以90度開始並旋轉回0,因爲看起來自動佈局功能首先啓動。這是我應該做的嗎?

或者我該如何重寫自動佈局功能,以便首先觸發轉換?

我只在模擬器中工作(等待漫長的App Hub註冊過程),因此很難看出這是否是正確的方法。

+0

VisualState有一個選項'Fluid Animation'。谷歌它... – Ku6opr 2011-12-31 15:13:52

+0

@ Ku6opr - 這種評論是不建設性的。如何鏈接到「流體動畫」選項?這個選項是一個DependencyProperty還是Blend中的某個UI元素? – 2011-12-31 16:43:08

+0

它是Expression Blend中Visual States面板右上角的按鈕。 http://www.microsoft.com/design/toolbox/tutorials/windows-phone-7/layout-tips/#FluidUI – Ku6opr 2011-12-31 18:04:20

回答

相關問題