Resource Keys can be anything, so you can use a Color
as a key and value at the same time:
public static class MyColors
{
static MyColors()
{
App.Current.Resources.Add(MyHighlightColorKey, MyHighlightColorKey);
}
public static readonly Color MyHighlightColorKey = Color.FromArgb(255, 0, 88, 0);
}
The static constructor adds the colour using itself as a key to the application resources.
(SystemColors
uses SystemResourceKeys
internally for every defined colour or brush, you have no access to that class however (which makes sense), alternatively you could subclass ResourceKey
if you take issue with using the value as its own key)
You can use it like this:
<TextBox>
<TextBox.Background>
<SolidColorBrush Color="{DynamicResource {x:Static local:MyColors.MyHighlightColorKey}}"/>
</TextBox.Background>
</TextBox>
And if you need to override the key on a local level you can do so as well:
<Window.Resources>
<Color x:Key="{x:Static local:MyColors.MyHighlightColorKey}" A="255" R="255" G="0" B="0"/>
</Window.Resources>
Edit: If you have lots of colours, brushes and whatnot you could also use reflection to do the resource registering in the constructor (i used fields, if you use properties to expose the data you need to adjust this slightly):
static MyColors()
{
FieldInfo[] keyFieldInfoArray = typeof(MyColors).GetFields();
foreach (var keyFieldInfo in keyFieldInfoArray)
{
object value = keyFieldInfo.GetValue(null);
App.Current.Resources.Add(value, value);
}
}