Share via


ThemeSettings 类

定义

ThemeSettings API 允许 Win32 Windows 运行时 应用检测系统的高对比度设置已更改。

public ref class ThemeSettings sealed
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.Foundation.WindowsAppSDKContract, 65540)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class ThemeSettings final
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.Foundation.WindowsAppSDKContract), 65540)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class ThemeSettings
Public NotInheritable Class ThemeSettings
继承
Object Platform::Object IInspectable ThemeSettings
属性

示例

在此示例代码中,应用使用 ThemeSettings 对象来侦听系统上的高对比度更改:

void MyApp::ListenForHighContrastChange(XamlRoot& xamlRoot) 
{
  const auto myWindowId = xamlRoot.ContentEnvironment().AppWindowId();
  m_themeSettings = ThemeSettings::CreateForWindowId(myWindowId);

  m_themeSettings.Changed([xamlRoot](const ThemeSettings& ts, const auto&) {
    if (ts.HighContrast())
    {
      ::OutputDebugString(L"High contrast is ON, scheme is: ");
      ::OutputDebugString(ts.HighContrastScheme().c_str());
    }
    else
    {
      ::OutputDebugString(L"High contrast is OFF.\n");
    }
  });
}
void MyApp.ListenForHighContrastChange(XamlRoot xamlRoot)
{
    var myWindowId = xamlRoot.ContentEnvironment().AppWindowId();
    m_themeSettings = ThemeSettings.CreateForWindowId(myWindowId);

    m_themeSettings.Changed += (ts, _) =>
    {
        if (ts.HighContrast())
        {
            Debug.WriteLine("High contrast is ON, scheme is: ");
            Debug.WriteLine(ts.HighContrastScheme());
        }
        else
        {
            Debug.WriteLine("High contrast is OFF.");
        }
    };
}

注解

当应用释放其对 ThemeSettings 对象的所有引用时,该对象将被销毁, 并且 Changed 事件将不再触发。

属性

HighContrast

获取当前的高对比度设置。

HighContrastScheme

系统的高对比度方案或样式(如果当前已应用)。

方法

CreateForWindowId(WindowId)

创建一个 ThemeSettings 对象,该对象将为给定的 WindowId 提供主题信息。

事件

Changed

ThemeSettings 对象的其中一个属性发生更改时,将引发此事件。

适用于

另请参阅