Bagikan melalui


UIViewSettings Kelas

Definisi

Mewakili status dan perilaku UI yang terkait dengan mode perangkat (Tablet atau Desktop) dan jenis perangkat input.

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 UIViewSettings
Public NotInheritable Class UIViewSettings
Warisan
Object Platform::Object IInspectable UIViewSettings
Atribut

Persyaratan Windows

Rangkaian perangkat
Windows 10 (diperkenalkan dalam 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (diperkenalkan dalam v1.0)

Contoh

Di sini, kami menunjukkan cara mendeteksi dan merespons mode interaksi pengguna.

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;
        }
    }
}

Keterangan

Untuk mendapatkan instans kelas ini, panggil GetForCurrentView.

Mode tablet (hanya Windows 10)

Catatan

Dalam Windows 11, mode Tablet dihapus dan fungsionalitas baru disertakan untuk postur pemasangan dan lepas keyboard.

Beberapa perangkat (PC, laptop, tablet) mendukung mode Desktop dan Tablet .

Hanya pada Windows 10, pengguna dapat beralih antara berjalan dalam mode Tablet dan mode Desktop dengan masuk ke mode Pengaturan > Tablet Sistem > dan mengatur Buat Windows lebih ramah sentuhan saat menggunakan perangkat Anda sebagai tablet.

Properti

UserInteractionMode

Mendapatkan nilai yang menunjukkan apakah UI perangkat dioptimalkan untuk input sentuhan atau input mouse.

Metode

GetForCurrentView()

Mendapatkan status dan perilaku UI yang terkait dengan mode perangkat (Tablet atau Desktop) untuk aplikasi aktif.

Mode tablet (hanya Windows 10)

Catatan

Dalam Windows 11, mode Tablet dihapus dan fungsionalitas baru disertakan untuk postur pemasangan dan lepas keyboard.

Beberapa perangkat (PC, laptop, tablet) mendukung mode Desktop dan Tablet .

Hanya pada Windows 10, pengguna dapat beralih antara berjalan dalam mode Tablet dan mode Desktop dengan masuk ke mode Pengaturan > Tablet Sistem > dan mengatur Buat Windows lebih ramah sentuhan saat menggunakan perangkat Anda sebagai tablet.

Berlaku untuk

Lihat juga