2012-12-05 115 views
2

我爲Windows RT設計了一個應用程序。我用VisualStateManager用於用戶控件。但是當我的應用程序捕捉時,用戶控件不會改變。哪裏有問題?用戶控制中的VisualStateManager

<Grid Width="500" Height="40" Margin="15" x:Name="questionRoot" Background="DarkSeaGreen"> 

    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" > 

     <TextBlock x:Name="OrginalWord" FontSize="32" Text="{Binding Question.OrginalWord}"></TextBlock> 

    </StackPanel> 
    <VisualStateManager.VisualStateGroups> 

     <!-- Visual states reflect the application's view state --> 
     <VisualStateGroup x:Name="ApplicationViewStates"> 
      <VisualState x:Name="FullScreenLandscape"/> 
      <VisualState x:Name="Filled"/> 

      <!-- The entire page respects the narrower 100-pixel margin convention for portrait --> 
      <VisualState x:Name="FullScreenPortrait"/> 
      <!-- 
       The back button and title have different styles when snapped, and the list representation is substituted 
       for the grid displayed in all other view states 
      --> 
      <VisualState x:Name="Snapped"> 
       <Storyboard> 

        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="OrginalWord" Storyboard.TargetProperty="FontSize"> 
         <DiscreteObjectKeyFrame KeyTime="0" Value="88"/> 
        </ObjectAnimationUsingKeyFrames> 



       </Storyboard> 
      </VisualState> 
     </VisualStateGroup> 
    </VisualStateManager.VisualStateGroups> 
</Grid> 

回答

1

你調用代碼隱藏的VisualStateManager.GoToState方法?您需要檢測應用程序何時從Full/Fill轉換爲Snap模式,然後調用此方法。

你會發現這個功能here的MSDN文檔。

當您的Page父控制或應用程序Window的大小更改時,您通常會認識到此轉換。 This SO question(查看Jowen的答案)爲您提供了關於如何通過偵聽窗口大小更改事件來完成此操作的代碼片段。

+0

感謝您的幫助,也許您可​​以回答這個問題 http://stackoverflow.com/questions/13680681/animation-for-control-visibility-in-windows-store-app-windows-8-metro – Mahdi

1

我有一個類似的問題,我發現了一個解決方案,幫助我,可能會有人覺得它有用,如果用戶控件在layoutawarepage託管

<my:usercontrole Loaded="StartLayoutUpdates" Unloaded="StopLayoutUpdates" /> 

,否則,你將不得不取消後續的(例如,可以發現在佈局意識到頁) •作出SizeChanged將

•事件處理程序事件處理程序檢查的視圖狀態與ApplicationView.Value

•移動到狀態VisualStateManager.GoToState