Пример #1
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType == typeof(string))
            {
                var solidBrush = value as C1SolidBrush;
                if (solidBrush != null)
                {
                    return(Utils.ColorToString(solidBrush.Color));
                }

                var linearBrush = value as C1LinearBrush;
                if (linearBrush != null)
                {
                    return("Linear Brush");
                }

                var radialBrush = value as C1RadialBrush;
                if (radialBrush != null)
                {
                    return("Radial Brush");
                }

                return("Transparent");
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }
Пример #2
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            var s = value as string;

            if (s == null)
            {
                return(base.ConvertFrom(context, culture, value));
            }

            if (string.IsNullOrEmpty(s))
            {
                return(new C1SolidBrush(Color.Transparent));
            }

            try
            {
                var color = Utils.ColorFromString(s);
                return(new C1SolidBrush(color));
            }
            catch (Exception)
            {
                throw new Exception(string.Format(Strings.BackgroundConverter.ErrorInvalidColor, s));
            }
        }