Reputation: 1352
I am trying to set a colour scheme in my XAML that can be altered by VB code in my app. I use Color and SolidColorBrush throughout the UI and they are defined like this:
<Color x:Key="PrimaryColour">#FFF7A619</Color>
<SolidColorBrush x:Key="PrimaryColourBrush" Color="{StaticResource PrimaryColour}"/>
I want to change all my SolidColorBrush and Color resources in my VB code to change the colour scheme.
I can change the SolidColorBrushes successfully like this:
TryCast(App.Current.Resources("PrimaryColourBrush"), SolidColorBrush).Color = ThisTeam.TeamPrimaryColour
In my ThisTeam class the colour is defined:
Public Property TeamPrimaryColour As Color = Colors.Purple
But I can't figure out how to do the same for Color resources. I've tried simply setting the resource like this:
App.Current.Resources("PrimaryColour") = ThisTeam.TeamPrimaryColour
And tried mimicking the TryCast that works for the brush with no luck. I'm totally lost. Everything I've tried results in a "NotImplementedException" error. FWIW the error always points to the next line in the code (i.e. not the line trying to set the colour), but it's clearly the colour line that is causing the exception.
Is what I'm trying even possible?
Thanks for any help or suggestions.
Upvotes: 2
Views: 432
Reputation: 11
You should take a look at the Coding4Fun toolkit:
It contains 3 tools that allow choosing/selecting a color.
Upvotes: 1