I am playing with this awesome helper Windows Phone Theme Manager in order to allow users to specify a different accent color from the phone's built-in one.
However, what I've found is that the method
ThemeManager.SetAccentColor(AccentColor.Red); doesn't work when I use Color resources instead of Brush ones in the xaml. For example, the first Grid below still uses the phone's accent color; while the second one uses whatever I defined in the SetAccentColor method.
<Grid x:Name="NotWorking"> <Grid.Background> <SolidColorBrush Color="{StaticResource PhoneAccentColor}"/> </Grid.Background> </Grid> <Grid x:Name="WorkingFine" Background="{StaticResource PhoneAccentBrush}"/> The problem seems to be in this particular method below (in this case the prefix is "PhoneAccent"). Because the Color resource is a value type, changing the currentColor doesn't have any impact to the actual resource.
internal static void SetOrCreateColorAndBrush(string prefix, Color color) { var currentColor = new Color(); // Check if the Colour is actually in the dictionary if (Application.Current.Resources.Contains(prefix + "Color")) { currentColor = (Color)Application.Current.Resources[prefix + "Color"]; currentColor.A = color.A; currentColor.B = color.B; currentColor.G = color.G; currentColor.R = color.R; } And then I tried setting the resource to color directly like this -
Application.Current.Resources[prefix + "Color"] = color; Only later I discovered this also wouldn't work because of this.
My last try was to remove this resource from Application.Current.Resources and add it back again with the color value. However for some reason that I don't know, this resource still could be found in the resources even after the Remove method...
Application.Current.Resources.Remove(prefix + "Color"); var stilReturnsTrue = Application.Current.Resources.Contains(prefix + "Color"); I am kinda running out of ideas here. Wonder if anyone has come across this and found any workarounds?
StaticResourceat all. The problem is how to set the value, not how to update the value on the UI. Note that theBrushone works fine.