从 xaml 中的一个画笔引用另一个画笔
是否可以直接引用资源字典中另一个画笔的画笔值,而不使用颜色定义(或者确切地说,将一个画笔资源复制到另一个画笔资源中)?
例如,我有一个画笔定义:
<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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道如何复制画笔本身,但正如你所说,你可以复制画笔的属性:
上面应该有相同的效果。
No way I know of to copy the brush itself, but as you say you can copy properties of the brush:
The above should have the same effect.
您可以执行以下操作:(
请注意,您可以在“颜色”中指定常规“颜色”属性)。
但是,如果您只是对多个 SolidColorBrush 对象使用相同的颜色,我想我会质疑为什么要这样做,除非是为了将来的灵活性。否则,您只会给自己带来额外的工作和可读性问题。
You can do something like this:
(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.