Answered by:
Changing the theme in SettingsFlyout

Question
-
I am using Tim Heuer's Callisto (https://github.com/timheuer/callisto) to provide a settings flyout. The settings flyout's main content is white, which according to Tim is the suggested model (http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/980d0b0d-61b2-4efd-88ff-2c04587c7397 search for color). However, my application's theme is dark, and when I put a ToggleSwitch in my settings fly out, I can see nothing, because it isn't aware that the settings fly out is in effect using the light theme, and is displaying everything as white. You can see this for yourself if you run Tim's test application and change requestedtheme in app.xaml to Dark. When you go to the settings fly out you can see nothing!
What can I do to tell the content within the settings fly out that I am in effect using the light theme for this part of the application?
...Stefan
Friday, May 18, 2012 2:21 AM
Answers
-
In the XAML framework, RequestedTheme cannot be changed when your app is running and only one value can be used at a time. The best thing you can do here is to apply an implicit style for the controls you use in your settings flyout. Installed with Visual Studio Express for Windows is a copy of the Generic.xaml file that the runtime uses. You can use that or use Blend to construct the implicit style. You can find it under: "\Program Files\windows kits\8.0\Include\winrt\xaml\design" on your computer. Note replace "program files" with the x86 version if you are on a x64 machine.
You'll primarily be interested in the ThemeDictionaries entry for Light theme to see what the light theme brushes are. Due to the nature of theme resources provided by the XAML runtime you cannot _override_ a theme resource (simple example - changing ToggleSwitchMouseOverCurtainBrush in "mySettingsFlyout.xaml" and have that be used). As such you'll need to rename the resources to not conflict with a system theme resource (in the Release Preview you'll notice that we made the naming convention easier to notice if the brush name is a theme resource). That is the only gotcha when attempting to copy the theme resource values in generic.xaml.
Hope this helps,
-mark
Program Manager
Microsoft
This post is provided "as-is"- Proposed as answer by Mark RideoutMicrosoft employee Friday, May 18, 2012 6:30 AM
- Marked as answer by StefanOlson Friday, May 18, 2012 10:14 PM
Friday, May 18, 2012 6:30 AM
All replies
-
In the XAML framework, RequestedTheme cannot be changed when your app is running and only one value can be used at a time. The best thing you can do here is to apply an implicit style for the controls you use in your settings flyout. Installed with Visual Studio Express for Windows is a copy of the Generic.xaml file that the runtime uses. You can use that or use Blend to construct the implicit style. You can find it under: "\Program Files\windows kits\8.0\Include\winrt\xaml\design" on your computer. Note replace "program files" with the x86 version if you are on a x64 machine.
You'll primarily be interested in the ThemeDictionaries entry for Light theme to see what the light theme brushes are. Due to the nature of theme resources provided by the XAML runtime you cannot _override_ a theme resource (simple example - changing ToggleSwitchMouseOverCurtainBrush in "mySettingsFlyout.xaml" and have that be used). As such you'll need to rename the resources to not conflict with a system theme resource (in the Release Preview you'll notice that we made the naming convention easier to notice if the brush name is a theme resource). That is the only gotcha when attempting to copy the theme resource values in generic.xaml.
Hope this helps,
-mark
Program Manager
Microsoft
This post is provided "as-is"- Proposed as answer by Mark RideoutMicrosoft employee Friday, May 18, 2012 6:30 AM
- Marked as answer by StefanOlson Friday, May 18, 2012 10:14 PM
Friday, May 18, 2012 6:30 AM -
Thanks Mark, I had noticed when testing a few other things that you can't override the theme resources simply, which is a bit of a shame. Certainly sounds like a lot of work to do something relatively simple, may just be simpler to use the dark theme in my settings flyout. I just always get fairly concerned about copying large amounts of XAML, as I have indicated one of my other postings, because the default template could be changed in a future release, leaving my controls looking incorrect.
Hopefully this sort of theme management can be improved in future releases, so that the ReqestedTheme can be specified at the control level. Ideally of course, WinRT would implement the DynamicResource feature from WPF, which was just outstanding for this sort of situation, although I'm aware that it did have performance implications.
...Stefan
Friday, May 18, 2012 10:14 PM -
Yeah hopefully DynamicResource feature from WPF can come sometime in "v.next". There are major perf issue with DynamicResources that we have to evaluate and potentially find another approach.
-mark
Program Manager
Microsoft
This post is provided "as-is"Friday, May 18, 2012 10:27 PM