I have a XAML application for Windows 8.1. I want users to customize the theme of the application themselves - for example, I want to give them a selection of colors where they can set different colors in the application, which will set different resources used in my application.
The problem though, I can’t find out how to dynamically change the value of a resource. I know that in 8.1 they added a theme resource concept that allows me to switch from a light to a dark theme at runtime and what not. But my problem is that I would like to say that "the backgroundColor resource will now be orange, and all elements using this resource reflect this change"
I believe the XAML DynamicResource element is what I need, but it looks like WPF and is not supported in Win8. Anyone have any suggestions?
You can change Color SolidColorBrushusing:
Color
SolidColorBrush
(Application.Current.Resources["BackgroundBrush"] as SolidColorBrush).Color = Colors.Orange;
This is because it SolidColorBrushis class, all elements have a link to it, changes in its properties will be reflected in all elements. But Coloris struct, therefore, changes XXXColorwill not work.
class
struct
XXXColor
I tested it only on Windows Runtime 8.1 APP, but it should also work on Windows Runtime 8.1 APP.
All application resources are stored in
Application.Current.Resources
. . , xaml, , , . , StaticResource, .
, , , .
Application.Current.Resources["HighlightThemeBrush"] = new SolidColorBrush(255, 168, 243, 108);
, , . , .