Share via


UIViewSettings.GetForCurrentView Method

Definition

Gets the UI states and behaviors associated with the device mode (Tablet or Desktop) for the active app.

Tablet mode (Windows 10 only)

Note

In Windows 11, Tablet mode is removed and new functionality is included for keyboard attach and detach postures.

Some devices (PC, laptop, tablet) support both a Desktop and Tablet mode.

On Windows 10 only, users can switch between running in Tablet mode and Desktop mode by going to Settings > System > Tablet mode and setting Make Windows more touch-friendly when using your device as a tablet.

public:
 static UIViewSettings ^ GetForCurrentView();
 static UIViewSettings GetForCurrentView();
public static UIViewSettings GetForCurrentView();
function getForCurrentView()
Public Shared Function GetForCurrentView () As UIViewSettings

Returns

A UIViewSettings instance that can be used to get and set view settings properties.

Examples

Here, we show how to use the interaction mode to optimize the app layout on launch or when the device mode is changed.

using Windows.UI.Xaml;
using Windows.UI.ViewManagement;

public sealed partial class MainPage : Page
{
  public MainPage()
  {
    InitializeComponent();
    // Every view gets an initial SizeChanged, so we will do all our 
    // work there. This means that our view also responds to dynamic
    // changes in user interaction mode.
    Window.Current.SizeChanged += SizeChanged;
  }

  private void SizeChanged(object sender, RoutedEventArgs e)
  {
    switch(UIViewSettings.GetForCurrentView().UserInteractionMode)
    {
      case UserInteractionMode.Mouse:
        VisualStateManager.GoToState(this, "MouseLayout", true);
        break;

      case UserInteractionMode.Touch:
      default:
        VisualStateManager.GoToState(this, "TouchLayout", true);
        break;
    }
  }
}

Applies to