/// <summary>Converts brushes in BrushCollection to LinearGradientBrush </summary>
        //public LinearGradientBrush ToGradientBrush()
        //{
        //    var colors = this.ToList();
        //    return colors.ToGradientBrush();
        //}
        public ColorCollection ReverseItems()
        {
            var newCollection = new ColorCollection();

            for (int i = this.Count - 1; i >= 0; i--)
            {
                var brush = this[i];
                newCollection.Add(brush);
            }
            return(newCollection);
        }
Beispiel #2
0
        /// <summary>
        /// TypeConverter method implementation that converts an object of type ColorCollection
        /// to an InstanceDescriptor or a string.  If the source is not a ColorCollection or
        /// the destination is not a string it forwards the call to
        /// TypeConverter.ConvertTo.
        /// </summary>
        /// <exception cref="NotSupportedException">
        /// A NotSupportedException is thrown if the example object is null
        /// or if the destinationType isn't one of the valid destination types.
        /// </exception>
        /// <param name="context">ITypeDescriptorContext</param>
        /// <param name="cultureInfo"> The CultureInfo which will govern this conversion. </param>
        /// <param name="value">value to convert from</param>
        /// <param name="destinationType">Type to convert to</param>
        /// <returns>converted value</returns>
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cultureInfo, object value, Type destinationType)
        {
            if (destinationType != null && value is ColorCollection)
            {
                ColorCollection instance = (ColorCollection)value;

                if (destinationType == typeof(string))
                {
                    // Delegate to the IFormatProvider version of ToString.
                    return(instance.ConvertToString(null, cultureInfo));
                }
            }

            // Pass unhandled cases to base class (which will throw exceptions for null value or destinationType.)
            return(base.ConvertTo(context, cultureInfo, value, destinationType));
        }
Beispiel #3
0
        /// <summary>
        /// Attempts to convert to a ColorCollection from the given object.
        /// </summary>
        /// <exception cref="NotSupportedException">
        /// A NotSupportedException is thrown if the example object is null or is not a valid type
        /// which can be converted to a ColorCollection.
        /// </exception>
        public override object ConvertFrom(ITypeDescriptorContext td, CultureInfo cultureInfo, object value)
        {
            if (value == null)
            {
                throw GetConvertFromException(value);
            }

            String source = value as string;

            if (source != null)
            {
                return(ColorCollection.Parse(source, cultureInfo));
            }
            else
            {
                return(base.ConvertFrom(td, cultureInfo, value));
            }
        }