36、UI contrast and settings

 在命名空间   Windows.UI.ViewManagement 中的 UISettings 类 :

namespace Windows.UI.ViewManagement
{   
     //包含一组常用 Metro 风格应用程序用户界面设置和操作。
      public sealed class UISettings
    {       
       // 创建 UISettings 类的新默认实例。
        public UISettings();
       
       //获取是否为用户界面启用动画。
        // 返回结果:  如果启用动画,则为 true;否则为 false。
        public bool AnimationsEnabled { get; }
       
       // 获取通过应用程序视图创建的新插入符号的闪烁速率。
        // 返回结果:  新插入符号的闪烁速率(以毫秒为单位)。
        public uint CaretBlinkRate { get; }
     
       //获取插入符号是否可用于浏览操作。
        // 返回结果: 如果插入符号可用于浏览操作,则为 true;否则为 false。
        public bool CaretBrowsingEnabled { get; }
        
       // 获取通过应用程序视图创建的新插入符号的宽度。
        // 返回结果: 新插入符号的宽度(以像素为单位)。
        public uint CaretWidth { get; }
      
       // 获取通过应用程序视图创建的新光标的大小。       
        // 返回结果: 新光标的大小。
        public Size CursorSize { get; }
      
        // 获取双击操作时两次单击之间的最长允许时间。
         // 返回结果: 双击操作的增量(以毫秒为单位)。
        public uint DoubleClickTime { get; }
      
       // 获取通过应用程序视图创建的用户界面的方向首选项。
        // 返回结果:  用户界面的方向首选项。
        public HandPreference HandPreference { get; }
      
       //获取为应用程序视图显示消息的时间长度。
       // 返回结果: 消息显示的持续时间(以秒为单位)。
        public uint MessageDuration { get; }
     
       // 获取在引发悬停事件之前,鼠标指针可悬停在矩形上的时间。       
        // 返回结果: 在悬停事件引发前的悬停时间(以毫秒为单位)。
        public uint MouseHoverTime { get; }
       
       // 获取与应用程序视图关联的窗口的滚动条箭头的大小。
        // 返回结果: 滚动条箭头的大小。
        public Size ScrollBarArrowSize { get; }
      
       // 获取与应用程序视图关联的窗口的滚动条的大小。       
        // 返回结果:  滚动条的大小。
        public Size ScrollBarSize { get; }
       
      //获取与应用程序视图关联的窗口的滚动块的大小。
       // 返回结果: 滚动框的大小。
        public Size ScrollBarThumbBoxSize { get; }

       // 获取用于特定用户界面元素类型(如按钮表面或窗口文本)的颜色。
        // desiredElement: 将获取颜色的元素类型。
        // 返回结果: 元素类型的颜色(以 32 位颜色值表示)。
        public Color UIElementColor(UIElementType desiredElement);
    }
}

AccessibilitySettings 类 :

namespace Windows.UI.ViewManagement
{
    
   //提供对高对比的辅助功能设置的访问。
    public sealed class AccessibilitySettings
    {
       // 初始化新的 AccessibilitySettings 对象。
        public AccessibilitySettings();

       //获取一个值,该值指示系统高对比度功能是打开还是关闭。
        // 返回结果: 如果高对比度功能处于打开状态,则为 true;否则为 false。
        public bool HighContrast { get; }
     
       //获取默认高对比度颜色方案的名称。      
        // 返回结果:  默认高对比度颜色方案的名称。
        public string HighContrastScheme { get; }

    
       // 在打开或关闭系统高对比度功能时发生。
        public event TypedEventHandler<AccessibilitySettings, object> HighContrastChanged;
    }
}


1、UI :

       演示了如何查询用户的各种UI设置。

页面的 xaml :

//输出结果
 <TextBlock x:Name="UIOutputTextBlock" TextWrapping="Wrap" />

在页面的 C# 页面 :

  protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            string Buffer;
            Windows.UI.ViewManagement.UISettings UserSettings = new Windows.UI.ViewManagement.UISettings();
            Windows.UI.Color Color;

            Buffer = string.Format("Hand Preference {0}\n", 
UserSettings.HandPreference ==
Windows.UI.ViewManagement.HandPreference.LeftHanded ? "left" : "right"); Buffer += string.Format("Cursor Size {0} x {1}\n", UserSettings.CursorSize.Width, UserSettings.CursorSize.Height); Buffer += string.Format("Scrollbar Size {0} x {1}\n",
UserSettings.ScrollBarSize.Width, UserSettings.ScrollBarSize.Height); Buffer
+= string.Format("Scrollbar Arrow Size {0} x {1}\n",
UserSettings.ScrollBarArrowSize.Width, UserSettings.ScrollBarArrowSize.Height); Buffer
+= string.Format("Scrollbar Thumb Box Size {0} x {1}\n",
UserSettings.ScrollBarThumbBoxSize.Width, UserSettings.ScrollBarThumbBoxSize.Height); Buffer
+= string.Format("Message Duration {0}\n", UserSettings.MessageDuration); Buffer += string.Format("Animations Enabled {0}\n", UserSettings.AnimationsEnabled ? "true" : "false"); Buffer += string.Format("Caret Browsing Enabled {0}\n", UserSettings.CaretBrowsingEnabled ? "true" : "false"); Buffer += string.Format("Caret Blink Rate {0}\n", UserSettings.CaretBlinkRate); Buffer += string.Format("Caret Width {0}\n", UserSettings.CaretWidth); Buffer += string.Format("Double Click Time {0}\n", UserSettings.DoubleClickTime); Buffer += string.Format("Mouse Hover Time {0}\n", UserSettings.MouseHoverTime); Buffer += "系统颜色: \n"; Color = UserSettings.UIElementColor(Windows.UI.ViewManagement.UIElementType.ActiveCaption); Buffer += string.Format("\tActive Caption: {0}, {1}, {2}\n", Color.R, Color.G, Color.B); Color = UserSettings.UIElementColor(Windows.UI.ViewManagement.UIElementType.Background); Buffer += string.Format("\tBackground: {0}, {1}, {2}\n", Color.R, Color.G, Color.B); Color = UserSettings.UIElementColor(Windows.UI.ViewManagement.UIElementType.ButtonFace); Buffer += string.Format("\tButton Face: {0}, {1}, {2}\n", Color.R, Color.G, Color.B); Color = UserSettings.UIElementColor(Windows.UI.ViewManagement.UIElementType.ButtonText); Buffer += string.Format("\tButton Text: {0}, {1}, {2}\n", Color.R, Color.G, Color.B); Color = UserSettings.UIElementColor(Windows.UI.ViewManagement.UIElementType.CaptionText); Buffer += string.Format("\tCaption Text: {0}, {1}, {2}\n", Color.R, Color.G, Color.B); Color = UserSettings.UIElementColor(Windows.UI.ViewManagement.UIElementType.GrayText); Buffer += string.Format("\tGray/Disabled Text: {0}, {1}, {2}\n", Color.R, Color.G, Color.B); Color = UserSettings.UIElementColor(Windows.UI.ViewManagement.UIElementType.Highlight); Buffer += string.Format("\tHighlight: {0}, {1}, {2}\n", Color.R, Color.G, Color.B); Color = UserSettings.UIElementColor(Windows.UI.ViewManagement.UIElementType.HighlightText); Buffer += string.Format("\tHighlighted Text: {0}, {1}, {2}\n", Color.R, Color.G, Color.B); Color = UserSettings.UIElementColor(Windows.UI.ViewManagement.UIElementType.Hotlight); Buffer += string.Format("\tHotlight: {0}, {1}, {2}\n", Color.R, Color.G, Color.B); Color = UserSettings.UIElementColor(Windows.UI.ViewManagement.UIElementType.InactiveCaption); Buffer += string.Format("\tInactive Caption: {0}, {1}, {2}\n", Color.R, Color.G, Color.B); Color = UserSettings.UIElementColor(Windows.UI.ViewManagement.UIElementType.InactiveCaptionText); Buffer += string.Format("\tInactive Caption Text: {0}, {1}, {2}\n", Color.R, Color.G, Color.B); Color = UserSettings.UIElementColor(Windows.UI.ViewManagement.UIElementType.Window); Buffer += string.Format("\tWindow: {0}, {1}, {2}\n", Color.R, Color.G, Color.B); Color = UserSettings.UIElementColor(Windows.UI.ViewManagement.UIElementType.WindowText); Buffer += string.Format("\tWindow Text: {0}, {1}, {2}\n", Color.R, Color.G, Color.B); UIOutputTextBlock.Text = Buffer; }

显示截图:

2、Accessibility :

    演示了如何查询用户的各种可访问性的设置。

在页面的 xaml :

//输出结果
 <TextBlock x:Name="AccessibilityOutputTextBlock"  TextWrapping="Wrap" />

相应的 C# :

protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            string Buffer;
           //提供对高对比的辅助功能设置的访问。
             Windows.UI.ViewManagement.AccessibilitySettings AccessibilitySettings = 
new Windows.UI.ViewManagement.AccessibilitySettings(); Buffer = string.Format("High Contrast mode is currently {0}\n",
AccessibilitySettings.HighContrast ? "enabled" : "disabled"); Buffer += string.Format("The specific high contrast scheme is {0}\n",
AccessibilitySettings.HighContrast ? AccessibilitySettings.HighContrastScheme : "currently undefined"); AccessibilityOutputTextBlock.Text = Buffer; }


显示截图 :

原文地址:https://www.cnblogs.com/hebeiDGL/p/2720309.html