views:

194

answers:

0

I'm trying to define a set of brushes using ComponentResourceKey notation that align themselves with the colors provided by the SystemColors object.

Here's what I know how to do (I have an example that follows):

1) I know how to define an inline brush that uses the SystemColors object (Brush1 in my example)

2) I know how to define and reference a brush with ComponentResourceKey (Brush2 in my example)

What I do not know is how to combine the two practices - have a Brush that is defined with the ComponentResourceKey notation, but references the SystemColors object (Brush3 in my example)

Here is my code:

<Window.Resources>
    <!--Brush 1) Using system colors in a simple brush--> 
    <SolidColorBrush
        x:Key="Brush1"
        Color="{DynamicResource {x:Static SystemColors.DesktopColorKey}}"
        />
    <!--Brush 2) Using ComponentResourceKey, hardcoded color-->
    <SolidColorBrush
        x:Key="{ComponentResourceKey {x:Type Border}, Brush2}"
        Color="Orange"
        />
    <!--Brush 1) Using system colors in a brush defined using ComponentResourceKey-->
    <SolidColorBrush
        x:Key="{ComponentResourceKey {x:Type Border}, Brush3}"
        Color="{DynamicResource {x:Static SystemColors.DesktopBrush}}"
        />
</Window.Resources>

<StackPanel>
    <!--Using Brush 1-->
    <Border
        Background="{StaticResource Brush1}"
        Height="20" BorderThickness="1" BorderBrush="Black" />
    <!--Using Brush 2-->
    <Border
        Background="{DynamicResource {ComponentResourceKey {x:Type Border}, Brush2}}"
        Height="20" BorderThickness="1" BorderBrush="Black" />
    <!--Using Brush 3-->
    <Border
        Background="{DynamicResource {ComponentResourceKey {x:Type Border}, Brush3}}"
        Height="20" BorderThickness="1" BorderBrush="Black" />
</StackPanel>

Everything seems to work piecemeal, but when I combine the two concepts it doesn't. I must be doing something wrong.

Any help would be greatly appreciated.