views:

28

answers:

2

Is it possible to directly reference to a Brush value from another Brush in my resource dictionary, without using a Color definition (or to be exact, copy one brush resource into another)?

For example, I have a Brush definition:

<SolidColorBrush x:Key="PanelBackgroundBrush" Color="White"/>

And I have a couple of other brushes I'd like to be exact the same as "PanelBackgroundBrush", something like so:

<SolidColorBrush x:Key="FolderColor" [BrushToCopy]="{StaticResource PanelBackgroundBrush}"/>

So that both "PanelBackgroundBrush" and "FolderColor" are using color white.

I understand this can be somehow achieved by using a common Color definition.

A: 

No way I know of to copy the brush itself, but as you say you can copy properties of the brush:

<SolidColorBrush x:Key="FolderColor" Color="{Binding Color, Source={StaticResource PanelBackgroundBrush}}"/>

The above should have the same effect.

HTH,
Kent

Kent Boogaart
A: 

You can do something like this:

<Color x:Key="colorCommon">Red</Color>
<SolidColorBrush x:Key="scb1" Color="{StaticResource colorCommon}" />
<SolidColorBrush x:Key="scb2" Color="{StaticResource colorCommon}" /> 

(Note that you could specify the regular Color properties in the Color).

However, if you are just using the same color with multiple SolidColorBrush objects, I guess I would question why you would do this, unless it is for some future flexibility. Otherwise, you are just creating extra work and readability issues for yourself.

Wonko the Sane