UIViewSettings 类 
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示与设备模式关联的 UI 状态和行为, (平板电脑或桌面) 和输入设备类型。
public ref class UIViewSettings sealed/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class UIViewSettings final[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class UIViewSettingsPublic NotInheritable Class UIViewSettings- 继承
- 属性
Windows 要求
| 设备系列 | 
							Windows 10 (在 10.0.10240.0 中引入) | 
| API contract | 
							Windows.Foundation.UniversalApiContract (在 v1.0 中引入) | 
示例
下面介绍如何检测和响应用户交互模式。
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;
        }
    }
}
注解
若要获取此类的实例,请调用 GetForCurrentView。
平板电脑模式仅 (Windows 10)
注意
在Windows 11,将删除平板电脑模式,并包含用于键盘连接和分离姿势的新功能。
(电脑、笔记本电脑、平板电脑) 的某些设备同时支持台式机和 平板电脑 模式。
仅Windows 10,用户可以通过转到“设置系统>平板电脑模式”和设置“>使 Windows 在将设备用作平板电脑时更便于触摸”,在平板电脑模式下切换运行。
属性
| UserInteractionMode | 获取一个值,该值指示设备 UI 是针对触摸输入还是鼠标输入进行优化。 | 
方法
| GetForCurrentView() | 获取与设备模式关联的 UI 状态和行为, (活动应用的平板电脑或桌面) 。 平板电脑模式仅 (Windows 10)注意 在Windows 11,将删除平板电脑模式,并包含用于键盘连接和分离姿势的新功能。 (电脑、笔记本电脑、平板电脑) 的某些设备同时支持台式机和 平板电脑 模式。 仅Windows 10,用户可以通过转到“设置系统>平板电脑模式”和设置“>使 Windows 在将设备用作平板电脑时更便于触摸”,在平板电脑模式下切换运行。 |