0
votes

I'm using themed resources:

<Page.Resources>
    <ResourceDictionary>
        <ResourceDictionary.ThemeDictionaries>
            <ResourceDictionary x:Key="Dark" Source="../Styles/Main/Dark.xaml" />
            <ResourceDictionary x:Key="Light" Source="../Styles/Main/Light.xaml" />
        </ResourceDictionary.ThemeDictionaries>
    </ResourceDictionary>
</Page.Resources>

This solution generally works - but only if theme was chosen before starting up the application. If user changes theme during application runtime, all themed colors (ones accessible via StaticResource) are refreshed correctly, but application still uses old theme dictionary (for instance, Dark, when user switched from Dark to Light).

How can I interrupt theme change and load valid theme dictionary?

1
ThemeResource is re-evaluated when theme changes, StaticResource is not. Are you sure the properties that are not changing are marked with ThemeResource and not StaticResource. See the remarks section here: msdn.microsoft.com/en-us/library/windows/apps/xaml/… - Bret Bentzinger
@BretBentzinger-MSFT This was the case, though I declared ResourceDictionaries as ThemeDictionaries, the actual resources were extracted by StaticResource. Now everything works. You may answer the question, such that I can accept it. - Spook

1 Answers

1
votes

The resources defined with ThemeResource should update automagically when the user changes the phone theme. Check out the remarks section here:

http://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn263118.aspx

Specifically:

"When the app first starts, any resource reference made by a ThemeResource reference is evaluated based on the theme in use at startup. But if the user subsequently changes the active theme at run-time, the system will re-evaluate every ThemeResource reference, retrieve a theme-specific resource that may be different, and redisplay the app with new resource values in all appropriate places in the visual tree."

Make sure to mark the resources in your Theme dictionaries as a ThemeResource and not a StaticResource.