/// <summary>
 /// Updates all controls that are listening for visual state changes with the correct
 /// visual state.
 /// </summary>
 /// <remarks>
 /// Typically used in conjunction with overriding <see cref="DetermineVisualState"/> to
 /// signal that a different value may be returned even though the view state has not
 /// changed.
 /// </remarks>
 public void InvalidateVisualState()
 {
     if (this._layoutAwareControls != null)
     {
         foreach (var layoutAwareControl in this._layoutAwareControls)
         {
             VisualStateManager.GoToState(layoutAwareControl, CurrentViewState.ToString(), false);
         }
     }
 }
        /// <summary>
        /// Invoked as an event handler, typically on the <see cref="FrameworkElement.Loaded"/>
        /// event of a <see cref="Control"/> within the page, to indicate that the sender should
        /// start receiving visual state management changes that correspond to application view
        /// state changes.
        /// </summary>
        /// <param name="sender">Instance of <see cref="Control"/> that supports visual state
        /// management corresponding to view states.</param>
        /// <param name="e">Event data that describes how the request was made.</param>
        /// <remarks>The current view state will immediately be used to set the corresponding
        /// visual state when layout updates are requested.  A corresponding
        /// <see cref="FrameworkElement.Unloaded"/> event handler connected to
        /// <see cref="StopLayoutUpdates"/> is strongly encouraged.  Instances of
        /// <see cref="LayoutAwarePage"/> automatically invoke these handlers in their Loaded and
        /// Unloaded events.</remarks>
        /// <seealso cref="DetermineVisualState"/>
        /// <seealso cref="InvalidateVisualState"/>
        public void StartLayoutUpdates(object sender, RoutedEventArgs e)
        {
            var control = sender as Control;

            if (control == null)
            {
                return;
            }
            if (this._layoutAwareControls == null)
            {
                // Start listening to view state changes when there are controls interested in updates
                Window.Current.SizeChanged += this.WindowSizeChanged;
                this._layoutAwareControls   = new List <Control>();
            }
            this._layoutAwareControls.Add(control);
            CurrentViewState = ViewStateHelper.GetViewState(ApplicationView.GetForCurrentView(), new Size(ActualWidth, ActualHeight));
            // Set the initial visual state of the control
            VisualStateManager.GoToState(control, CurrentViewState.ToString(), false);
        }