Esempio n. 1
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            string s = (string)value;

            if (s.StartsWith("#"))
            {
                s = s.Substring(1);

                if (s.Length == 6)
                {
                    s = "ff" + s;
                }

                if (s.Length != 8)
                {
                    throw new NotSupportedException("Invalid color string.");
                }

                return(new SolidColorBrush(Color.FromUInt32(uint.Parse(s, NumberStyles.HexNumber))));
            }
            else
            {
                PropertyInfo p = typeof(Colors).GetProperty(s, BindingFlags.Public | BindingFlags.Static);

                if (p != null)
                {
                    return(new SolidColorBrush((Color)p.GetValue(null)));
                }
                else
                {
                    throw new NotSupportedException();
                }
            }
        }
Esempio n. 2
0
 public static Color ToColor(this KnownColor color)
 {
     return(Color.FromUInt32((uint)color));
 }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SolidColorBrush"/> class.
 /// </summary>
 /// <param name="color">The color to use.</param>
 public SolidColorBrush(uint color)
     : this(Color.FromUInt32(color))
 {
 }