I'm wanting to change the color of a rectangle depending on what theme the user has chosen on their phone.
EG. When the user has their device's theme color set to light a rectangle should be blue and when the theme is set to dark it should be a grey.
Any ideas?
Thanks
This kind of thing would be able to determine what the theme is set to (dark or light). You might want to build it into a property that you can bind to for your brush.
You can also get the user's selected accent colour with the
PhoneAccentBrush
if you need to take that into account as well.I wrote a custom resource dictionary implementation which selects another dictionary at runtime without a performance penalty and works in the Visual Studio designer. You would use it like this:
Where
Light.xaml
andDark.xaml
would contain resources with the same names.You can get the code and read more about it on my blog.