I don't know if someone already have done something similar but I am often stuck because there is no event when the user change the Theme of the app (from Dark to Light for example).
In a recent project, I was stuck because I could not change the color in a composition animation when a user changed the theme.
I don't think this is possible in WinRT.
Let me add a flag for the XAML team. Perhaps they have more insights on this one.
Application theme can only be set in App constructor. When the app is loaded, you can't change it at all. It's by design. Attempting to set RequestedTheme while the app is running will throw NotSupportedException.
However, there's a trick that some of the official apps are using like Groove. Application based theme changing is not allowed but Page based theme changing is fine. I needed it as well a while ago and what I did was apply the theme in the base page constructor. I would say it's costly, but not as costly if you add runtime theme capability to the pros side.
There's no way to actually handle it afaik and it makes sense because uwp don't have the runtime theme changing support :)
I guess that this is about WP, where users can change the phone theme during runtime. Apps will adapt to the theme change on-the-fly, unless they explicitly set App.RequestedTheme during startup.
I do not know of an official way to get a notification for this. It might be possible to create a kind of "hack", where you bind a property of your ViewModel to a ThemeResource binding and observe when it changes.
Shouldn't it be possible to use Leaving/Entering background events to determine if the theme has changed and then fire subscribed events?
@Romasz I don't think this is the right way to do it and there is no right way until official sdk has this support imo.
There has to be something that we don't know on the official part, I don't think they forgot to support :) Of course it is doable, but taking an action without knowing anything about the reason behind should not be in our part.
If you are using resources within xaml these should change automatically when the theme changes. If you need to know outside of that look at ColorsChanged event.
@bkaankose Yeah, I know that it's just way round, though it's doable (even have couple of ideas) and I also doesn't know official way. I'm also not sure if it should be implemented here.
@timheuer ThemeResources are working fine, though in some cases something like themechanged event is needed. I tried to search for ColorsChanged event in docs without success, do you have any link to it?
@Romasz ColorValuesChanged sorry https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.viewmanagement.uisettings.colorvalueschanged.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1
@timheuer Thanks, haven't run across it yet.
I think we should close this one now as I don't believe there's anything we can do for the toolkit. If I'm wrong, please reopen.
I was able to create a pretty good listener class for this in my project.
I would like to see that on the Toolkit.
ping @nmetulev
As noted by @timheuer there is already a way for devs to hook into this. Not sure adding something to the toolkit is going to help
@skendrot Yes but ColorValuesChanged is not ThemeChanged.
Correct. But if that's the best there is right now...
@skendrot What do you mean?
@hawkerm's ThemeListener is making it into the Toolkit via #1650.
@WilliamABradley Wonderful!
Most helpful comment
I was able to create a pretty good listener class for this in my project.