Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference to another Brush from one Brush in xaml

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.

like image 564
mobileTofu Avatar asked Oct 25 '10 15:10

mobileTofu


2 Answers

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.

like image 98
Kent Boogaart Avatar answered Sep 22 '22 18:09

Kent Boogaart


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.

like image 37
Wonko the Sane Avatar answered Sep 22 '22 18:09

Wonko the Sane