private void SetVisualState(Size controlSize)
        {
            var state = ViewStateHelper.GetViewState(ApplicationView.GetForCurrentView(), controlSize);

            CurrentViewState = state;
            VisualStateManager.GoToState(this, state.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);
        }
 private void WindowSizeChanged(object sender, WindowSizeChangedEventArgs e)
 {
     CurrentViewState = ViewStateHelper.GetViewState(ApplicationView.GetForCurrentView(), e.Size);
     this.InvalidateVisualState();
     OnSizeChanged(ApplicationView.GetForCurrentView());
 }