コード例 #1
0
        /// <summary>
        ///   Attempts to convert a RibbonControlLength instance to the given type.
        /// </summary>
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType == null)
            {
                throw new ArgumentNullException("destinationType");
            }

            if (value != null && value is RibbonControlLength)
            {
                RibbonControlLength length = (RibbonControlLength)value;

                if (destinationType == typeof(string))
                {
                    return(ToString(length, culture));
                }

                if (destinationType == typeof(InstanceDescriptor))
                {
                    ConstructorInfo ci = typeof(RibbonControlLength).GetConstructor(new Type[] { typeof(double), typeof(RibbonControlLengthUnitType) });
                    return(new InstanceDescriptor(ci, new object[] { length.Value, length.RibbonControlLengthUnitType }));
                }
            }

            throw GetConvertToException(value, destinationType);
        }
コード例 #2
0
        private static bool ValidateWidth(object width)
        {
            RibbonControlLength length = (RibbonControlLength)width;

            if (double.IsInfinity(length.Value) || DoubleUtil.LessThanOrClose(length.Value, 0))
            {
                return(false);
            }
            return(true);
        }
コード例 #3
0
        private static bool ValidateMaxWidth(object maxWidth)
        {
            RibbonControlLength length = (RibbonControlLength)maxWidth;

            if (length.IsAuto || length.IsStar || DoubleUtil.LessThan(length.Value, 0))
            {
                return(false);
            }
            return(true);
        }
コード例 #4
0
        /// <summary>
        ///   Converts a RibbonControlLength instance to a String given the CultureInfo.
        /// </summary>
        internal static string ToString(RibbonControlLength length, CultureInfo cultureInfo)
        {
            switch (length.RibbonControlLengthUnitType)
            {
            //  for Auto print out "Auto". value is always "1.0"
            case RibbonControlLengthUnitType.Auto:
                return("Auto");

            case RibbonControlLengthUnitType.Item:
                return(Convert.ToString(length.Value, cultureInfo) + "items");

            //  Star has one special case when value is "1.0".
            //  in this case drop value part and print only "Star"
            case RibbonControlLengthUnitType.Star:
                return(DoubleUtil.IsOne(length.Value) ? "*" : Convert.ToString(length.Value, cultureInfo) + "*");

            //  for Pixel print out the numeric value. "px" can be omitted.
            default:
                return(Convert.ToString(length.Value, cultureInfo));
            }
        }