How to detect Silverlight color by color component in XAML?

I am trying to set the color of my Silverlight control as a slightly transparent version of the color defined in my ResourceDictionary used by my application.

To do this, my strategy was to split the color into components so that I could capture the RGB values ​​and then set my own alpha value for me to get a translucent color.

ResourceDictionary looks something like this:

<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}" />

....

Then my color will be used in my application, indicating the color or its components.

....

<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>

....

My problem:

Silverlight XAML, -, : , , ResourceDictionary, "type" Byte "not found".

, A, R, G, B , , ? ( ?) , , , / , -? , XAML.

?

+3
1

, .

:

public class ChangeAlphaConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        var color = (Color) value;
        color.A = byte.Parse((string) parameter);
        return color;
    }
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

:

<UserControl.Resources>
    <Color x:Key="BaseColor">#fff</Color>
    <SilverlightTests:ChangeAlphaConverter x:Key="ChangeAlpha"/>
</UserControl.Resources>
...
    <Border>
        <Border.Background>
            <SolidColorBrush Color="{Binding Source={StaticResource BaseColor}, Converter={StaticResource ChangeAlpha}, ConverterParameter=100}"/>
        </Border.Background>
    </Border>

( BaseColor) 100 ()

+1

All Articles