从 xaml 中的一个画笔引用另一个画笔

发布于 2024-09-28 15:27:06 字数 444 浏览 2 评论 0原文

是否可以直接引用资源字典中另一个画笔的画笔值,而不使用颜色定义(或者确切地说,将一个画笔资源复制到另一个画笔资源中)?

例如,我有一个画笔定义:

<SolidColorBrush x:Key="PanelBackgroundBrush" Color="White"/>

我还有几个其他画笔,我希望与“PanelBackgroundBrush”完全相同,如下所示:

<SolidColorBrush x:Key="FolderColor" [BrushToCopy]="{StaticResource PanelBackgroundBrush}"/>

因此“PanelBackgroundBrush”和“FolderColor”都使用白色。

我知道这可以通过使用通用的颜色定义来实现。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟酒忠诚 2024-10-05 15:27:06

我不知道如何复制画笔本身,但正如你所说,你可以复制画笔的属性:

<SolidColorBrush x:Key="FolderColor" Color="{Binding Color, Source={StaticResource PanelBackgroundBrush}}"/>

上面应该有相同的效果。

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.

一袭水袖舞倾城 2024-10-05 15:27:06

您可以执行以下操作:(

<Color x:Key="colorCommon">Red</Color>
<SolidColorBrush x:Key="scb1" Color="{StaticResource colorCommon}" />
<SolidColorBrush x:Key="scb2" Color="{StaticResource colorCommon}" /> 

请注意,您可以在“颜色”中指定常规“颜色”属性)。

但是,如果您只是对多个 SolidColorBrush 对象使用相同的颜色,我想我会质疑为什么要这样做,除非是为了将来的灵活性。否则,您只会给自己带来额外的工作和可读性问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文