Ejemplo n.º 1
0
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            Color color;

            if (value is Color)
            {
                color = (Color)value;
            }
            else if (value is String)
            {
                color = ColorUtilities.FromString((string)value);
            }
            else if (value is SolidColorBrush)
            {
                color = ((SolidColorBrush)value).Color;
            }

            if (parameter != null)
            {
                var parameters = parameter.ToString().GetConverterParameters();
                if (parameters.ContainsKey("alpha"))
                {
                    color = ColorUtilities.ChangeAlpha(color, parameters["alpha"]);
                }
            }

            if (targetType == typeof(Brush))
            {
                return(new SolidColorBrush(color));
            }
            if (targetType == typeof(Color))
            {
                return(color);
            }
            if (targetType == typeof(string))
            {
                return(ColorUtilities.ToHex(color, true));
            }
            return(null);
        }