我将尝试将我的Silverlight控件的颜色设置为应用程序中使用的ResourceDictionary中定义的颜色的略微透明版本。
为此,我打算将颜色分成组件,以便可以获取RGB值,然后在其上设置自己的alpha值,以获得半透明颜色。
ResourceDictionary类似于:
然后,我的应用程序会通过引用颜色或其组件来使用我的颜色。
为此,我打算将颜色分成组件,以便可以获取RGB值,然后在其上设置自己的alpha值,以获得半透明颜色。
ResourceDictionary类似于:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<system:Byte x:Key="PrimaryLightColorAlphaValue">#FF</system:Byte>
<system:Byte x:Key="PrimaryLightColorRedValue">#DB</system:Byte>
<system:Byte x:Key="PrimaryLightColorGreenValue">#E5</system:Byte>
<system:Byte x:Key="PrimaryLightColorBlueValue">#F1</system:Byte>
<Color x:Name="PrimaryLightColor" A="{StaticResource PrimaryLightColorAlphaValue}"
R="{StaticResource PrimaryLightColorRedValue}"
G="{StaticResource PrimaryLightColorGreenValue}"
B="{StaticResource PrimaryLightColorBlueValue}" />
<SolidColorBrush x:Name="PrimaryLightColorBrush" Color="{StaticResource PrimaryLightColor}" />
....
然后,我的应用程序会通过引用颜色或其组件来使用我的颜色。
....
<Border Background="{StaticResource PrimaryLightColorBrush}" />
....
<LinearColorKeyFrame KeyTime="00:00:00">
<LinearColorKeyFrame.Value>
<Color A="#CC"
R="{StaticResource PrimaryLightColorBrushRedValue}"
G="{StaticResource PrimaryLightColorBrushGreenValue}"
B="{StaticResource PrimaryLightColorBrushBlueValue}" />
</LinearColorKeyFrame.Value>
</LinearColorKeyFrame>
....
我的问题:
Silverlight XAML似乎不支持Byte类型:因此在ResourceDictionary中定义的颜色部分从未加载,并抛出“未找到类型'Byte'”的错误。
那么我该如何实现将A、R、G、B颜色值分解为字节的等效方法,而不使用字节?(使用字符串和类型转换?)或者也许有更好的方法来定义一个颜色,继承/使用它,然后覆盖其Alpha值?关键是我需要通过XAML实现这一点。
有什么想法吗?