Partager via


How to determine theme colors from a Direct3D app for Windows Phone 8

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

This topic shows you how to determine the phone’s current theme colors from a Windows Phone Direct3D app. Users can customize their phone by selecting a primary accent color, but also by choosing a light or dark theme, or by choosing a high-contrast theme that a user might find easier to read. The following table lists the UI element types that you can query in a Windows Phone Direct3D app. These theme colors are defined in the UIElementType enumeration. There are other theme colors in this enumeration that are used by other platforms, but the elements in the table are the only ones supported on the phone. Attempting to query a value not in the table will cause an exception to be thrown.

UI element type

Description

AccentColor

The phone's accent color.

TextHigh

High-contrast text.

TextMedium

Medium-contrast text.

TextLow

Low-contrast text.

TextContrastWithHigh

Text that contrasts with TextHigh.

NonTextHigh

High-contrast non-text content.

NonTextMediumHigh

Medium-high contrast non-text content.

NonTextMedium

Medium-contrast non-text content.

NonTextMediumLow

Medium-low contrast non-text content.

NonTextLow

Low-contrast non-text content.

PageBackground

The background of a normal page.

PopupBackground

The background of a pop-up dialog.

OverlayOutsidePopup

The partially opaque color applied to the area of the screen outside of a pop-up window to dim the background and highlight the dialog.

Example

This code sample shows you how to get the current theme’s accent color.

    auto settings = ref new UISettings();
    Windows::UI::Color accentColor = settings->UIElementColor(UIElementType::AccentColor);

It is possible for the user to switch their theme color while your app is running. If you want to handle this case, you can add a call to query the theme colors to the handler for the Resuming event, which is provided by the Direct3D app project template. This handler will be invoked if the user switches to the Settings app, and then returns to your app.