2017-01-31 9 views
1

テンプレート10のデフォルトのビジュアル状態の基準を変更するにはどうすればよいですか?[template10]の新しいvisualstate

携帯電話のランドスケープモードとPCやタブレットのウィンドウを区別できるようにしたいと考えています。

NormalMinWidthは、電話機を横向きモードにすることによってトリガーされます。問題は、ランドスケープモードでの電話画面の高さが、タブレットまたはパソコンよりもはるかに低い可能性があるということです。

電話機のNormalMinWidthとパソコンやタブレットのレイアウトが異なるようにしたいと思います。たとえば、最小画面の高さを探す別の視覚状態NormalMinWidthMinHeightを追加したいとします。

ご提案いただければ幸いです。

答えて

1

状態を動的に変更できるコードを実装する必要があります。

たとえば、現在のビューの向きに基づいて状態を変更する場合は、 OrientationChangedイベントのイベントハンドラを実装し、VisualStateManagerクラスのGoToStateメソッドを使用する必要があります。

参考のために次のコードサンプルを参照してください:あなたの答えのための

<VisualStateManager.VisualStateGroups> 
     <VisualStateGroup x:Name="AdaptiveVisualStateGroup"> 

      <VisualState x:Name="VisualMinWidthHeight"> 
       <VisualState.Setters> 
        <Setter Target="stateTextBox.Text" Value="Visual Min Width Height" /> 
       </VisualState.Setters> 
      </VisualState> 
     </VisualStateGroup> 
</VisualStateManager.VisualStateGroups> 
<TextBlock x:Name="stateTextBox" Text="Current Visual State" /> 
DisplayInformation.GetForCurrentView().OrientationChanged += MainPage_OrientationChanged; 

private void MainPage_OrientationChanged(DisplayInformation info, object args) 
{ 
    Debug.WriteLine("orientation: " + info.CurrentOrientation); 
    if (info.CurrentOrientation == DisplayOrientations.LandscapeFlipped || info.CurrentOrientation == DisplayOrientations.Landscape) 
    { 
     VisualStateManager.GoToState(this, "VisualMinWidthHeight", true); 
    } 
} 
+0

感謝を。私は、質問を説明する良い仕事をしたとは思わない。 Template10フレームワークでは、VisualStateManager.GoToStateを呼び出すコードはどこにありますか?これを延長できますか?視覚的な状態の変化を待ち受けるために、各ページにコードを入れてGotoStateを呼び出す必要はありません。私はこれがブートストラップにあるかもしれませんが、私はそこにそれを見ませんでした。 – Sully

+2

@Sullyいいですよ。上記のコードは単純な解決策または提案でした。あなたの参照のためだけです。 [StateTriggerBase](https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.statetriggerbase.aspx)を拡張して独自のカスタムトリガを作成し、StateTriggers内で使用することもできますプロパティ。 [State triggers sample](https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/XamlStateTriggers)では、カスタムトリガーの作成方法について説明しています。詳細は、参照することができます。 –

+0

ありがとうXavier – Sully