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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With