Custom State Trigger

  1. Create a „Triggers“ Folder in the Project.
  2. Create a Class e.g. „OrientationTrigger.cs“

C# Code

class OrientationTrigger : StateTriggerBase
{
  public OrientationTrigger()
  {
    Window.Current.SizeChange += (s, e) =>
    {
      SetActive(ApplicationView.GetForCurrentView().Orientation.Equals(this.Orientation));
    }

    public ApplicationViewOrientation Orientation { get; set; }
  }
}

 

XAML

  1. Create States
  2. „VisualStateLandscape“
    1. „VisualStatePortrait“
  3. Insert Namespace  Definition xmlns:t=“using:apppsname.Triggers“
  4. Use Trigger:
<VisualState.StateTriggers>
  <t:OrientationTrigger Orientation="Landscape" />
<VisualState.StateTriggers>