开发者

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 "F开发者_如何学GoolderColor" are using color white.

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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜