How to point one resource (a SolidColorBrush) at another

Andy T picture Andy T · Mar 30, 2011 · Viewed 11.2k times · Source

I set up a load of SolidColorBrush and LinearGradientBrush resources in a ResourceDictionary. I used these as I was restyling several controls for use in our application.

Now I have a bunch of other external brushes that I have to use for a variation on our app. These are also set up in a ReseourceDictionary.

Is it possible to point my brush resources at the new resources in another dictionary, something similar to the "BasedOn" attribute of Styles?

Something like this, conceptually at least:

<SolidColorBrush x:Key="MyDataGridHeaderBrush" Binding="HeaderBrushDefinedElsewhere"/>

...or is this kind of thing not possible, in which case I have to simply go do a Find/Replace and replace all my brush names with the new brush names?

Thanks in advance,

AT

Answer

markmuetz picture markmuetz · Mar 30, 2011

I agree with what Rachel said, but if you have to base it on an existing SolidColorBrush, you can do it with the following:

<SolidColorBrush x:Key="MyDataGridHeaderBrush" 
                 Color="{Binding Source={StaticResource HeaderBrushDefinedElsewhere}, Path=Color}"/>

Note this just works for the "Color" attribute, you'd have to do it separately for each attribute you needed.