How to point one resource (a SolidColorBrush) at another How to point one resource (a SolidColorBrush) at another wpf wpf

How to point one resource (a SolidColorBrush) at another


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.


Usually I do a static Color property in one place, and have my brushes bind to that Color.

<SolidColorBrush x:Key="LightColor" Color="#C5DBF6"/><SolidColorBrush x:Key="DarkColor" Color="#FF8DB2E3"/><LinearGradientBrush x:Key="FadeOutRight" EndPoint="1,1" StartPoint="0,0">        <GradientStop Color="{Binding Source={StaticResource LightColor}, Path=Color}" Offset="0" />        <GradientStop Color="{Binding Source={StaticResource DarkColor}, Path=Color}" Offset="1"/></LinearGradientBrush>

You can also bind other SolidBrushColors to this:

<SolidColorBrush Color="{Binding Source={StaticResource LightColor}, Path=Color}" />

If this is referenced in another file, it might underline it because it can't find the static resource, but at runtime it will still compile providing your main resource file containing your brush definitions is loaded.