public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            string str = value as string;
            if (str == null)
            {
                return base.ConvertFrom(context, culture, value);
            }
            str = str.Trim();
            if (str.Length == 0) return null;

            string[] sizes = str.Split(',');
            RibbonSizeCollection collection = new RibbonSizeCollection();
            foreach (string size in sizes)
            {
                RibbonSize rs;
                switch (size.ToUpper())
                {
                    case "L": rs = RibbonSize.Large; break;
                    case "M": rs = RibbonSize.Medium; break;
                    case "S": rs = RibbonSize.Small; break;
                    case "0": rs = RibbonSize.Minimized; break;


                    default:
                        rs = (RibbonSize)Enum.Parse(typeof(RibbonSize), size, true);
                        break;
                }
                collection.Add(rs);
            }
            return collection;
        }
Exemplo n.º 2
0
        //Gets the maximum possible ReductionLevel that would change any of the controls.
        private int GetMaxLevel()
        {
            int max = 1;

            foreach (UIElement e in Controls)
            {
                if (e is IRibbonControl)
                {
                    RibbonSizeCollection reduction = RibbonBar.GetReduction(e);
                    int m = reduction != null ? reduction.Count : 3;
                    max = Math.Max(max, m);
                }
                if (e is IRibbonGallery)
                {
                    RibbonGalleryColumns columns = RibbonGallery.GetReductionColumns(e);
                    int m = columns != null ? columns.Count : 3;
                    max = Math.Max(max, m);
                }
            }
            return(max);
        }
        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            string str = value as string;

            if (str == null)
            {
                return(base.ConvertFrom(context, culture, value));
            }
            str = str.Trim();
            if (str.Length == 0)
            {
                return(null);
            }

            string[]             sizes      = str.Split(',');
            RibbonSizeCollection collection = new RibbonSizeCollection();

            foreach (string size in sizes)
            {
                RibbonSize rs;
                switch (size.ToUpper())
                {
                case "L": rs = RibbonSize.Large; break;

                case "M": rs = RibbonSize.Medium; break;

                case "S": rs = RibbonSize.Small; break;

                case "0": rs = RibbonSize.Minimized; break;


                default:
                    rs = (RibbonSize)Enum.Parse(typeof(RibbonSize), size, true);
                    break;
                }
                collection.Add(rs);
            }
            return(collection);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the RibbonSize for a control for a specific level.
        /// </summary>
        /// <param name="control">The control for which to retreive a RibbonSize.</param>
        /// <param name="level">The reduction Level (0=large, 2=medium,3=small,4=minimized,...).</param>
        /// <param name="index">The index of the control in the group.</param>
        /// <returns>The RibbonSize for the control.</returns>
        RibbonSize GetControlSize(DependencyObject control, int level, int index)
        {
            RibbonSizeCollection reductions = RibbonBar.GetReduction(control);

            if (reductions != null && reductions.Count > 0)
            {
                level = Math.Max(0, Math.Min(level, reductions.Count - 1));
                return(reductions[level]);
            }
            RibbonSize size;

            switch (level)
            {
            case 0: size = GetDefaultSizeForLevel0(index); break;

            case 1: size = GetDefaultSizeForLevel1(index); break;

            case 2: size = GetDefaultSizeForLevel2(index); break;

            default: size = RibbonSize.Minimized; break;
            }

            RibbonSize min = RibbonBar.GetMinSize(control);
            RibbonSize max = RibbonBar.GetMaxSize(control);

            if (size < min)
            {
                size = min;
            }
            if (size > max)
            {
                size = max;
            }

            return(size);
        }
Exemplo n.º 5
0
 public static void SetReduction(DependencyObject obj, RibbonSizeCollection value)
 {
     obj.SetValue(ReductionProperty, value);
 }