My questions is very specific to ThemeResources in a Windows 10 Store App. Unfortunately several things available in "classic" WPF are different or not available here.
What I am trying to achieve for lots of ui elements:
{ThemeResource SystemAccentColor}
as value.)SystemAccentColor
key in the resourcedictionary)But I have not found a good solution to achieve all of this. If I have my own resource dictionary with the custom color, I won't get rid of it when the user would like to switch back to the system's accent color.
And using a property I am binding against has the drawback that I do not realize if the user changes the accent color in the system settings while the app is running - using the {ThemeResource}
markup it does.
Any ideas how to get this done properly?
If it would be possible to set the ThemeResource
from code I could write some behavior for this, but it seems not to be available.
There is a way how to kinda set ThemeResource
in code... I've tested it only on W10 Creators Update so it may not work on older versions, but you can create your own resource that is referencing the original ThemeResource
you want to use and then use this resource:
XAML:
<SolidColorBrush x:Key="MyBorderBrush" Color="{ThemeResource SystemAccentColor}"/>
C#:
element.BorderBrush = (SolidColorBrush)Resources["MyBorderBrush"];
The border color of element
will be the same as the Accent Color selected in Windows Settings and it will change even when your app is running and user changes it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With