言語

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.ContentIslandEnvironment().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.ContentIslandEnvironment().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)

指定された WindowId のテーマ情報を提供する ThemeSettings オブジェクトを作成します。

イベント

名前 説明
Changed

このイベントは、 ThemeSettings オブジェクトのプロパティのいずれかが変更されたときに発生します。

適用対象

こちらもご覧ください