static void OnDialogLauncherButtonKeyTipKeysChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { RibbonGroupBox ribbonGroupBox = (RibbonGroupBox)d; if (ribbonGroupBox.LauncherButton != null) { KeyTip.SetKeys(ribbonGroupBox.LauncherButton, (string)e.NewValue); } }
private static object CoerceIsDropDownOpen(DependencyObject d, object basevalue) { RibbonGroupBox box = d as RibbonGroupBox; if ((box.State != RibbonGroupBoxState.Collapsed) && (box.State != RibbonGroupBoxState.QuickAccess)) { return(false); } return(basevalue); }
/// <summary> /// Handles IsOpen propertyu changes /// </summary> /// <param name="d">Object</param> /// <param name="e">The event data</param> static void OnIsOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { RibbonGroupBox ribbon = (RibbonGroupBox)d; if (ribbon.IsDropDownOpen) { ribbon.OnRibbonGroupBoxPopupOpening(); } else { ribbon.OnRibbonGroupBoxPopupClosing(); } }
private void OnQuickAccessClosed(object sender, EventArgs e) { RibbonGroupBox groupBox = sender as RibbonGroupBox; for (int i = 0; i < groupBox.Items.Count; i++) { object item = groupBox.Items[0]; groupBox.Items.Remove(item); Items.Add(item); i--; } IsSnapped = false; }
private static void OnIconChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { RibbonGroupBox element = d as RibbonGroupBox; FrameworkElement oldElement = e.OldValue as FrameworkElement; if (oldElement != null) { element.RemoveLogicalChild(oldElement); } FrameworkElement newElement = e.NewValue as FrameworkElement; if (newElement != null) { element.AddLogicalChild(newElement); } }
private void OnQuickAccessOpened(object sender, EventArgs e) { if ((!IsDropDownOpen) && (!IsSnapped)) { RibbonGroupBox groupBox = sender as RibbonGroupBox; // Save state IsSnapped = true; for (int i = 0; i < Items.Count; i++) { object item = Items[0]; Items.Remove(item); groupBox.Items.Add(item); i--; } } }
/// <summary> /// Gets parent RibbonGroupBox or null /// </summary> /// <param name="element"></param> /// <returns></returns> static RibbonGroupBox GetGroupBox(DependencyObject element) { if (element == null) { return(null); } RibbonGroupBox groupBox = element as RibbonGroupBox; if (groupBox != null) { return(groupBox); } DependencyObject parent = VisualTreeHelper.GetParent(element); return(GetGroupBox(parent)); }
/// <summary> /// Gets control which represents shortcut item. /// This item MUST be syncronized with the original /// and send command to original one control. /// </summary> /// <returns>Control which represents shortcut item</returns> public FrameworkElement CreateQuickAccessItem() { RibbonGroupBox groupBox = new RibbonGroupBox(); groupBox.DropDownOpened += OnQuickAccessOpened; groupBox.DropDownClosed += OnQuickAccessClosed; groupBox.State = RibbonGroupBoxState.QuickAccess; //RibbonControl.BindQuickAccessItem(this, groupBox); //if (QuickAccessElementStyle != null) RibbonControl.Bind(this, groupBox, "QuickAccessElementStyle", StyleProperty, BindingMode.OneWay); //RibbonControl.Bind(this, groupBox, "Icon", RibbonControl.IconProperty, BindingMode.OneWay); RibbonControl.Bind(this, groupBox, "LauncherCommandParameter", LauncherCommandParameterProperty, BindingMode.OneWay); RibbonControl.Bind(this, groupBox, "LauncherCommand", LauncherCommandProperty, BindingMode.OneWay); RibbonControl.Bind(this, groupBox, "LauncherCommandTarget", LauncherCommandTargetProperty, BindingMode.OneWay); RibbonControl.Bind(this, groupBox, "LauncherIcon", LauncherIconProperty, BindingMode.OneWay); RibbonControl.Bind(this, groupBox, "LauncherText", LauncherTextProperty, BindingMode.OneWay); RibbonControl.Bind(this, groupBox, "LauncherToolTip", LauncherToolTipProperty, BindingMode.OneWay); RibbonControl.Bind(this, groupBox, "IsLauncherEnabled", IsLauncherEnabledProperty, BindingMode.OneWay); RibbonControl.Bind(this, groupBox, "IsLauncherVisible", IsLauncherVisibleProperty, BindingMode.OneWay); RibbonControl.Bind(this, groupBox, "DialogLauncherButtonKeyTipKeys", DialogLauncherButtonKeyTipKeysProperty, BindingMode.OneWay); groupBox.LauncherClick += this.LauncherClick; if (Icon != null) { Visual iconVisual = Icon as Visual; if (iconVisual != null) { Rectangle rect = new Rectangle(); rect.Width = 16; rect.Height = 16; rect.Fill = new VisualBrush(iconVisual); groupBox.Icon = rect; } else { RibbonControl.Bind(this, groupBox, "Icon", RibbonControl.IconProperty, BindingMode.OneWay); } } if (Header != null) { RibbonControl.Bind(this, groupBox, "Header", RibbonControl.HeaderProperty, BindingMode.OneWay); } return(groupBox); }
// Decrease size of the item void DecreaseGroupBoxSize(string name) { RibbonGroupBox groupBox = FindGroup(name); bool scale = name.StartsWith("(", StringComparison.OrdinalIgnoreCase); if (groupBox == null) { return; } if (scale) { groupBox.ScaleIntermediate--; } else { groupBox.StateIntermediate = (groupBox.StateIntermediate != RibbonGroupBoxState.Collapsed) ? groupBox.StateIntermediate + 1 : groupBox.StateIntermediate; } }
Size GetChildrenDesiredSizeIntermediate() { double width = 0; double height = 0; foreach (UIElement child in this.InternalChildren) { RibbonGroupBox groupBox = child as RibbonGroupBox; if (groupBox == null) { continue; } Size desiredSize = groupBox.DesiredSizeIntermediate; width += desiredSize.Width; height = Math.Max(height, desiredSize.Height); } return(new Size(width, height)); }
// Handles visibility changed private static void OnVisibilityChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { RibbonGroupBox box = (d as RibbonGroupBox); box.ClearCache(); }
/// <summary> /// Measures all of the RibbonGroupBox, and resize them appropriately /// to fit within the available room /// </summary> /// <param name="availableSize">The available size that this element can give to child elements.</param> /// <returns>The size that the groups container determines it needs during /// layout, based on its calculations of child element sizes. /// </returns> protected override Size MeasureOverride(Size availableSize) { Size infinitySize = new Size(Double.PositiveInfinity, availableSize.Height); Size desiredSize = GetChildrenDesiredSizeIntermediate(); if (reduceOrder.Length == 0) { VerifyScrollData(availableSize.Width, desiredSize.Width); return(desiredSize); } // If we have more available space - try to expand groups while (desiredSize.Width <= availableSize.Width) { bool hasMoreVariants = reduceOrderIndex < reduceOrder.Length - 1; if (!hasMoreVariants) { break; } // Increase size of another item reduceOrderIndex++; IncreaseGroupBoxSize(reduceOrder[reduceOrderIndex]); desiredSize = GetChildrenDesiredSizeIntermediate(); } // If not enough space - go to next variant while (desiredSize.Width > availableSize.Width) { bool hasMoreVariants = reduceOrderIndex >= 0; if (!hasMoreVariants) { break; } // Decrease size of another item DecreaseGroupBoxSize(reduceOrder[reduceOrderIndex]); reduceOrderIndex--; desiredSize = GetChildrenDesiredSizeIntermediate(); } // Set find values foreach (object item in InternalChildren) { RibbonGroupBox groupBox = item as RibbonGroupBox; if (groupBox == null) { continue; } if ((groupBox.State != groupBox.StateIntermediate) || (groupBox.Scale != groupBox.ScaleIntermediate)) { groupBox.SuppressCacheReseting = true; groupBox.State = groupBox.StateIntermediate; groupBox.Scale = groupBox.ScaleIntermediate; groupBox.InvalidateLayout(); groupBox.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); groupBox.SuppressCacheReseting = false; } // Something wrong with cache? if (groupBox.DesiredSizeIntermediate != groupBox.DesiredSize) { // Reset cache and reinvoke masure groupBox.ClearCache(); return(MeasureOverride(availableSize)); } } VerifyScrollData(availableSize.Width, desiredSize.Width); return(desiredSize); }
// Find key tips on the given element private void FindKeyTips(UIElement element, bool hide) { this.Log("FindKeyTips"); IEnumerable children = LogicalTreeHelper.GetChildren(element); foreach (object item in children) { UIElement child = item as UIElement; RibbonGroupBox groupBox = (child as RibbonGroupBox); if (child != null) { string keys = KeyTip.GetKeys(child); if (keys != null) { // Gotcha! KeyTip keyTip = new KeyTip { Content = keys, Visibility = hide ? Visibility.Collapsed : Visibility.Visible }; // Add to list & visual // children collections keyTips.Add(keyTip); base.AddVisualChild(keyTip); associatedElements.Add(child); if (groupBox != null) { if (groupBox.State == RibbonGroupBoxState.Collapsed) { keyTip.Visibility = Visibility.Visible; FindKeyTips(child, true); continue; } else { keyTip.Visibility = Visibility.Collapsed; } } else { // Bind IsEnabled property Binding binding = new Binding("IsEnabled") { Source = child, Mode = BindingMode.OneWay }; keyTip.SetBinding(UIElement.IsEnabledProperty, binding); continue; } } if ((groupBox != null) && (groupBox.State == RibbonGroupBoxState.Collapsed)) { FindKeyTips(child, true); } else { FindKeyTips(child, hide); } } } }