ThemeSettings Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
The ThemeSettings API allows Win32 Windows Runtime apps to detect that the system's High Contrast setting has changed.
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
- Inheritance
- Attributes
Examples
In this sample code, an app uses a ThemeSettings object to listen for high contrast changes on the system:
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.");
}
};
}
Remarks
When the app releases all its references to a ThemeSettings object, the object will be destroyed and the Changed event will no longer fire.
Properties
HighContrast |
Gets the current High Contrast setting. |
HighContrastScheme |
The High Contrast scheme or style of the system, if one is currently applied. |
Methods
CreateForWindowId(WindowId) |
Creates a ThemeSettings object that will provide theme information for the given WindowId. |
Events
Changed |
This event is raised when one of the ThemeSettings object's properties has changed. |