UIViewSettings Class

Definition

Represents UI states and behaviors associated with the device mode (Tablet or Desktop) and input device type.

public ref class UIViewSettings sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Static(Windows.UI.ViewManagement.IUIViewSettingsStatics, 65536, Windows.Foundation.UniversalApiContract)]
class UIViewSettings final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Static(Windows.UI.ViewManagement.IUIViewSettingsStatics, 65536, "Windows.Foundation.UniversalApiContract")]
class UIViewSettings final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Static(Windows.UI.ViewManagement.IUIViewSettingsStatics, 65536, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.DualApiPartition(version=167772160)]
class UIViewSettings final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Static(typeof(Windows.UI.ViewManagement.IUIViewSettingsStatics), 65536, typeof(Windows.Foundation.UniversalApiContract))]
public sealed class UIViewSettings
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Static(typeof(Windows.UI.ViewManagement.IUIViewSettingsStatics), 65536, "Windows.Foundation.UniversalApiContract")]
public sealed class UIViewSettings
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Static(typeof(Windows.UI.ViewManagement.IUIViewSettingsStatics), 65536, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.DualApiPartition(version=167772160)]
public sealed class UIViewSettings
Public NotInheritable Class UIViewSettings
Inheritance
UIViewSettings
Attributes

Windows 10 requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

Examples

Here, we show how to detect and respond to the user interaction mode.

using System.ComponentModel;
using Windows.UI.Core;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;

namespace SDKTemplate
{
    public sealed partial class Scenario1_Basic : Page, INotifyPropertyChanged
    {
        private MainPage rootPage;

        public Scenario1_Basic()
        {
            this.InitializeComponent();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            rootPage = MainPage.Current;

            // The SizeChanged event is raised when the
            // user interaction mode changes.
            Window.Current.SizeChanged += OnWindowResize;
            UpdateContent();
        }

        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            Window.Current.SizeChanged -= OnWindowResize;
        }

        void OnWindowResize(object sender, WindowSizeChangedEventArgs e)
        {
            UpdateContent();
        }

        public event PropertyChangedEventHandler PropertyChanged;

        #region InteractionMode data binding
        private UserInteractionMode interactionMode;

        public UserInteractionMode InteractionMode
        {
            get { return interactionMode; }
            set
            {
                if (interactionMode != value)
                {
                    interactionMode = value;
                    if (PropertyChanged != null)
                    {
                        PropertyChanged(this, 
                            new PropertyChangedEventArgs("InteractionMode"));
                    }
                }
            }
        }

        #region CheckBoxStyle data binding
        private Style checkBoxStyle;

        public Style CheckBoxStyle
        {
            get { return checkBoxStyle; }
            set
            {
                if (checkBoxStyle != value)
                {
                    checkBoxStyle = value;
                    if (PropertyChanged != null)
                    {
                        PropertyChanged(this, 
                            new PropertyChangedEventArgs("CheckBoxStyle"));
                    }
                }
            }
        }

        void UpdateContent()
        {
            InteractionMode = 
                UIViewSettings.GetForCurrentView().UserInteractionMode;

            // Update styles
            CheckBoxStyle = 
                InteractionMode == 
                    UserInteractionMode.Mouse ? 
                        MouseCheckBoxStyle : TouchCheckBoxStyle;
        }
    }
}

Remarks

To get an instance of this class, call GetForCurrentView.

Note

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

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.

Properties

UserInteractionMode

Gets a value that indicates whether the device UI is optimized for touch input or mouse input.

Methods

GetForCurrentView()

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

Note

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

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.

Applies to