int GetGalleryColumns(DependencyObject control, int level, int maxLevels) { RibbonGalleryColumns columns = RibbonGallery.GetReductionColumns(control); if (columns != null && columns.Count > 0) { level = Math.Max(0, Math.Min(level, columns.Count - 1)); return(columns[level]); } if (level == maxLevels) { return(0); } if (maxLevels > 4) { level = Math.Max(level, 8); return(3 + (4 - level / 2)); } else { return(3 + (2 - level) * 2); } }
//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); }