locked
[Universal App] Detecting Theme Change

    Question

  • Hi all,

    In my universal app, users can change the background color of the application. The default background color is the ApplicationPageBackgroundThemeBrush. This can be retrieved in C# as follows:

    Application.Current.Resources["ApplicationPageBackgroundThemeBrush"]

    The problem I'm experiencing occurs when the user switches out of the application, changes system themes, and then switches back to the application. Let's take this scenario as an example:

    1. Background theme color = Dark Gray
    2. User switches out of app and goes to the Control Panel to change the theme
    3. User changes the theme from "None" to "High Contrast White"
    4. Background theme color = White
    5. User switches back to the app. The background color is still Dark Gray but should be White

    I am having trouble finding an event for step #5. At the point the user switches back to the app, I would like to detect the current theme and then change the background color accordingly. The OnLaunched event in App.xaml.cs doesn't get fired, and neither does the Page's OnNavigatedTo event. The Window.Current.VisibilityChanged event occurs, but I feel there may be a better solution.

    Any insight on this issue would be greatly appreciated!

    Sunday, May 25, 2014 2:31 AM

Answers

  • Hello Alexander,

    That could be a great idea to detect if user switch between normal Windows Themes, but I have to say currently there is no such implementation for Windows Store Apps.

    However, if you only want to detect high contrast mode that are set for system, that could be easier, we have this: Supporting high-contrast themes. This event HighContrastChanged will be fired when someone set the high constrast mode for system, this one could be a solution for your step 5.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, May 26, 2014 6:45 AM
    Moderator

All replies

  • Hello Alexander,

    That could be a great idea to detect if user switch between normal Windows Themes, but I have to say currently there is no such implementation for Windows Store Apps.

    However, if you only want to detect high contrast mode that are set for system, that could be easier, we have this: Supporting high-contrast themes. This event HighContrastChanged will be fired when someone set the high constrast mode for system, this one could be a solution for your step 5.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, May 26, 2014 6:45 AM
    Moderator
  • Hi James,

    Thank you for your reply! This should work fine for my purposes, but would this tutorial also account for a theme switch (light > dark or dark > light) in Windows Phone?

    Thanks again,

    Alex

    Monday, May 26, 2014 8:09 PM
  • Hi Alex,

    Probably you could ask question at Windows Phone forum for a better support http://social.msdn.microsoft.com/Forums/wpapps/en-us/home?category=wpapps.

    I'm not familiar with Windows Phone development, but per documentation, this API is a new feature for Windows Phone 8.1, hope this helps.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, May 27, 2014 1:15 AM
    Moderator