剥皮:使用颜色作为另一种颜色的静态资源 [英] Skinning: Using a Color as StaticResource for another Color

查看:185
本文介绍了剥皮:使用颜色作为另一种颜色的静态资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中实现了皮肤。应用程序加载它的Brushes.xaml资源字典,它使用驻留在特定于皮肤的资源字典中的颜色。因此,根据所选的皮肤,只会加载一个Color.xaml。



Skin-Specific Color.xaml

 < Color x:Key =TextBoxBackgroundColor>#C4AF8D< / Color> 
< Color x:Key =TextBoxForegroundColor>#6B4E2C< / Color>
< Color x:Key =ToolBarButtonForegroundColor>#6B4E2C< / Color>

Brushes.xaml:

 < SolidColorBrush 
x:Key =TextBoxBackground
Color ={DynamicResource TextBoxBackgroundColor}/>
< SolidColorBrush
x:Key =TextBoxForeground
Color ={DynamicResource TextBoxForegroundColor}/>

正如你所看到的,多种颜色(TextBoxForegroundColor和ToolBarButtonForegroundColor)是一样的。我想绕开它,因为它变得越来越混乱,特别是因为使用的颜色是不可识别的十六进制值。你可以建议现在将两个颜色合并为一个,但我有皮肤的TextBoxForegroundColor不同于ToolBarButtonForegroundColor。



我想做的是这样的: / p>

 < Color x:Key =DarkBrown>#C4AF8D< / Color> 

< Color x:Key =TextBoxBackgroundColorColor = {StaticResource DarkBrown} />
< Color x:Key =ToolBarButtonForegroundColorColor = {StaticResource DarkBrown} />

这在Xaml是可能的吗?我没有找到办法。


解决方案

$ p> < Color x:Key =DarkBrown>#C4AF8D< / Color>

< DynamicResource x:Key =TextBoxBackgroundColorResourceKey =DarkBrown/>
< DynamicResource x:Key =ToolBarButtonForegroundColorResourceKey =DarkBrown/>

(顺便说一句)


I implemented skinning in my application. The application loads its Brushes.xaml resource dictionary which uses colors which reside in a skin-specific resource dictionary. So only one Color.xaml is loaded depending on the chosen skin.

Skin-Specific Color.xaml

    <Color x:Key="TextBoxBackgroundColor">#C4AF8D</Color>
    <Color x:Key="TextBoxForegroundColor">#6B4E2C</Color>
    <Color x:Key="ToolBarButtonForegroundColor">#6B4E2C</Color>

Brushes.xaml:

    <SolidColorBrush 
        x:Key="TextBoxBackground" 
        Color="{DynamicResource TextBoxBackgroundColor}" />
    <SolidColorBrush 
        x:Key="TextBoxForeground" 
        Color="{DynamicResource TextBoxForegroundColor}" />

As you can see, multiple colors (TextBoxForegroundColor and ToolBarButtonForegroundColor) are the same. I'd like to circumvent that as it is getting more and more confusing especially since the used colors are not recognizable by their hex value. You could advise now to merge both Colors into one but I have skins where the TextBoxForegroundColor is different from the ToolBarButtonForegroundColor.

What I would like to do is something like this:

<Color x:Key="DarkBrown">#C4AF8D</Color>

<Color x:Key="TextBoxBackgroundColor" Color={StaticResource DarkBrown} />
<Color x:Key="ToolBarButtonForegroundColor" Color={StaticResource DarkBrown} />

Is this at all possible in Xaml? I didn't find a way.

解决方案

This?

<Color x:Key="DarkBrown">#C4AF8D</Color>

<DynamicResource x:Key="TextBoxBackgroundColor" ResourceKey="DarkBrown"/>
<DynamicResource x:Key="ToolBarButtonForegroundColor" ResourceKey="DarkBrown"/>

(Works by the way)

这篇关于剥皮:使用颜色作为另一种颜色的静态资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆