ThemeSettings 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
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
- 繼承
- 屬性
範例
在此範例程式碼中,應用程式會使用 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 物件的所有參考時,將會終結物件,且 已變更 事件將不再引發。
屬性
HighContrast |
取得目前的高對比設定。 |
HighContrastScheme |
如果目前已套用高對比配置或系統樣式,則為 。 |
方法
CreateForWindowId(WindowId) |
建立 ThemeSettings 物件,以提供指定 WindowId的主題資訊。 |
事件
Changed |
當其中一個 ThemeSettings 物件的屬性變更時,就會引發這個事件。 |