title: Bind VisualStateManager VisualState to view model?
body: <p>I have Grid with three different VisualState's. How would I bind this info to my view model as I need to do thing differently depending on view state.</p>
  
  <p>Right now Im using CurrentStateChanged event (which is not very mvvm way) but the major issue is that the event is not fired when the app is opened, so I do not know the initial visual state.</p>
  
  <p>My current view:</p>
  
  <pre><code>&lt;VisualStateManager.VisualStateGroups&gt;
      &lt;VisualStateGroup x:Name="AdaptiveVisualStateGroup" CurrentStateChanged="{x:Bind ViewModel.ViewStateChanged, Mode=OneWay}"&gt;
          &lt;VisualState x:Name="VisualStateNarrow"&gt;
              &lt;VisualState.StateTriggers&gt;
                  &lt;AdaptiveTrigger MinWindowWidth="0" /&gt;
              &lt;/VisualState.StateTriggers&gt;
              &lt;VisualState.Setters&gt;
              ...
              &lt;/VisualState.Setters&gt;
          &lt;/VisualState&gt;
          &lt;VisualState x:Name="VisualStateNormal"&gt;
              &lt;VisualState.StateTriggers&gt;
                  &lt;AdaptiveTrigger MinWindowWidth="720" /&gt;
              &lt;/VisualState.StateTriggers&gt;
              &lt;VisualState.Setters&gt;
              ...
              &lt;/VisualState.Setters&gt;
          &lt;/VisualState&gt;
          &lt;VisualState x:Name="VisualStateWide"&gt;
              &lt;VisualState.StateTriggers&gt;
                  &lt;AdaptiveTrigger MinWindowWidth="1000" /&gt;
              &lt;/VisualState.StateTriggers&gt;
              &lt;VisualState.Setters&gt;
              ...
              &lt;/VisualState.Setters&gt;
          &lt;/VisualState&gt;
      &lt;/VisualStateGroup&gt;
  &lt;/VisualStateManager.VisualStateGroups&gt;
  </code></pre>
  
  <p>View model:</p>
  
  <pre><code>public void ViewStateChanged(object sender, VisualStateChangedEventArgs args)
  {
      if(args.NewState.Name == "VisualStateNarrow")
      {
          isNarrowState = true;
      }
      ...
  }
  </code></pre>