2012-04-21 37 views
4

我想使用VisualStateManager將屬性值設置爲屬性。問題是我需要在嵌套元素(稱爲variableSizedWrapGrid)上設置此值,但它不響應相應的狀態。這個想法是當用戶改變平板電腦的方向(橫向到縱向)並且應該改變這個元素的方向。如何設置嵌套元素的可視化狀態?

<GroupStyle.Panel> 
    <ItemsPanelTemplate> 
     <VariableSizedWrapGrid x:Name="variableSizedWrapGrid" Orientation="Vertical" Background="Blue" Width="660" ItemHeight="120" ItemWidth="220" Margin="0,0,80,0"> 

      <VisualStateManager.VisualStateGroups> 
       <VisualStateGroup> 
        <VisualState x:Name="FullScreenPortrait"> 
         <Storyboard> 
          <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Orientation)"> 
           <DiscreteObjectKeyFrame KeyTime="0" Value="Horizontal" /> 
          </ObjectAnimationUsingKeyFrames> 
         </Storyboard> 
        </VisualState> 
       </VisualStateGroup> 
      </VisualStateManager.VisualStateGroups> 

     </VariableSizedWrapGrid> 

    </ItemsPanelTemplate> 
</GroupStyle.Panel> 

我正在開發一個Windows Metro應用的Windows 8

回答

1

我相信這是個什麼LayoutAwarePage是。如果您有一個LayoutAwarePage作爲基類,並且您希望控件在平板電腦旋轉時切換VisualState,則將控件的Loaded事件掛接到LayoutAwarePage上的StartLayoutUpdates方法。如你所見,只要狀態改變,它就會運行「InvalidateVisualState」,它將通過所有接收LayoutUpdates的控件,並手動將他們的VisualStateManager設置爲適當的狀態。

所以在你有的代碼中,你需要爲風景設置一個VisualState - 我相信這將被稱爲FullScreenLandscape,但我不記得 - 然後將StartLayoutUpdates添加到VariableSizedWrapGrid控件的Loaded事件。這假設你的頁面是一個LayoutAwarePage。說實話,你應該這樣做,如果你想這樣做。由於這個原因,他們已經包含了所有的樣板代碼。

希望有所幫助。