private void UpdateChildSizes() { var groupBoxState = this.State == RibbonGroupBoxState.QuickAccess ? RibbonGroupBoxState.Collapsed : this.State; foreach (var item in this.Items) { var element = this.ItemContainerGenerator.ContainerFromItem(item); RibbonProperties.SetAppropriateSize(element, groupBoxState); } }
/// <summary> /// Gets control which represents shortcut item. /// This item MUST be synchronized with the original /// and send command to original one control. /// </summary> /// <returns>Control which represents shortcut item</returns> public override FrameworkElement CreateQuickAccessItem() { SplitButton button = new SplitButton(); button.Click += ((sender, e) => this.RaiseEvent(e)); RibbonProperties.SetSize(button, RibbonControlSize.Small); button.CanAddButtonToQuickAccessToolBar = false; this.BindQuickAccessItem(button); this.BindQuickAccessItemDropDownEvents(button); button.DropDownOpened += this.OnQuickAccessOpened; this._quickAccessButton = button; return(button); }
/// <inheritdoc /> public override FrameworkElement CreateQuickAccessItem() { var buttonForQAT = new SplitButton { CanAddButtonToQuickAccessToolBar = false }; buttonForQAT.Click += (sender, e) => this.RaiseEvent(e); buttonForQAT.DropDownOpened += this.OnQuickAccessOpened; RibbonProperties.SetSize(buttonForQAT, RibbonControlSize.Small); this.BindQuickAccessItem(buttonForQAT); this.BindQuickAccessItemDropDownEvents(buttonForQAT); this.quickAccessButton = buttonForQAT; return(buttonForQAT); }
private void UpdateWindowChrome() { var windowChrome = WindowChrome.GetWindowChrome(this); if (windowChrome == null) { windowChrome = new WindowChrome(); WindowChrome.SetWindowChrome(this, windowChrome); } windowChrome.CaptionHeight = RibbonProperties.GetTitleBarHeight(this); windowChrome.CornerRadius = this.CornerRadius; windowChrome.GlassFrameThickness = this.GlassBorderThickness; windowChrome.ResizeBorderThickness = this.ResizeBorderThickness; #if NET45 windowChrome.UseAeroCaptionButtons = this.CanUseDwm; #endif }
/// <summary> /// Gets control which represents shortcut item. /// This item MUST be synchronized with the original /// and send command to original one control. /// </summary> /// <returns>Control which represents shortcut item</returns> public virtual FrameworkElement CreateQuickAccessItem() { var button = new DropDownButton(); RibbonProperties.SetSize(button, RibbonControlSize.Small); BindQuickAccessItem(button); RibbonControl.Bind(this, button, "DisplayMemberPath", DisplayMemberPathProperty, BindingMode.OneWay); RibbonControl.Bind(this, button, "GroupStyleSelector", GroupStyleSelectorProperty, BindingMode.OneWay); RibbonControl.Bind(this, button, "ItemContainerStyle", ItemContainerStyleProperty, BindingMode.OneWay); RibbonControl.Bind(this, button, "ItemsPanel", ItemsPanelProperty, BindingMode.OneWay); RibbonControl.Bind(this, button, "ItemStringFormat", ItemStringFormatProperty, BindingMode.OneWay); RibbonControl.Bind(this, button, "ItemTemplate", ItemTemplateProperty, BindingMode.OneWay); RibbonControl.Bind(this, button, "MaxDropDownHeight", MaxDropDownHeightProperty, BindingMode.OneWay); BindQuickAccessItemDropDownEvents(button); button.DropDownOpened += OnQuickAccessOpened; return(button); }
// Size change to collapse ribbon private void OnSizeChanged(object sender, SizeChangedEventArgs e) { this.MaintainIsCollapsed(); if (this.iconImage != null && this.ActualWidth <= 140D + RibbonProperties.GetLastVisibleWidth(this.iconImage).GetZeroIfInfinityOrNaN() + RibbonProperties.GetLastVisibleWidth(this.WindowCommands.ItemsControl).GetZeroIfInfinityOrNaN()) { this.SetCurrentValue(IsIconVisibleProperty, false); this.TitleBar.SetCurrentValue(VisibilityProperty, Visibility.Collapsed); this.WindowCommands.SetCurrentValue(WindowCommands.ItemsPanelVisibilityProperty, Visibility.Collapsed); } else { this.InvalidateProperty(IsIconVisibleProperty); this.iconImage.SetValue(RibbonProperties.LastVisibleWidthProperty, this.iconImage.ActualWidth); this.TitleBar.InvalidateProperty(VisibilityProperty); this.WindowCommands.InvalidateProperty(WindowCommands.ItemsPanelVisibilityProperty); this.WindowCommands.ItemsControl.SetValue(RibbonProperties.LastVisibleWidthProperty, this.WindowCommands.ItemsControl.ActualWidth); } }
/// <summary> /// Gets current used layout definition (or null if no present definitions) /// </summary> /// <returns>Layout definition or null</returns> internal RibbonToolBarLayoutDefinition GetCurrentLayoutDefinition() { if (layoutDefinitions.Count == 0) { return(null); } if (layoutDefinitions.Count == 1) { return(layoutDefinitions[0]); } foreach (RibbonToolBarLayoutDefinition definition in layoutDefinitions) { if (RibbonProperties.GetSize(definition) == RibbonProperties.GetSize(this)) { return(definition); } } // TODO: try to find a better definition return(layoutDefinitions[0]); }
public RibbonToolBarControlDefinition() { RibbonProperties.SetSize(this, RibbonControlSize.Small); }
/// <summary> /// Binds default properties of control to quick access element /// </summary> /// <param name="source">Source item</param> /// <param name="element">Toolbar item</param> public static void BindQuickAccessItem(FrameworkElement source, FrameworkElement element) { Bind(source, element, nameof(source.DataContext), DataContextProperty, BindingMode.OneWay); if (source is ICommandSource) { if (source is MenuItem) { Bind(source, element, nameof(ICommandSource.CommandParameter), System.Windows.Controls.MenuItem.CommandParameterProperty, BindingMode.OneWay); Bind(source, element, nameof(ICommandSource.CommandTarget), System.Windows.Controls.MenuItem.CommandTargetProperty, BindingMode.OneWay); Bind(source, element, nameof(ICommandSource.Command), System.Windows.Controls.MenuItem.CommandProperty, BindingMode.OneWay); } else { Bind(source, element, nameof(ICommandSource.CommandParameter), ButtonBase.CommandParameterProperty, BindingMode.OneWay); Bind(source, element, nameof(ICommandSource.CommandTarget), ButtonBase.CommandTargetProperty, BindingMode.OneWay); Bind(source, element, nameof(ICommandSource.Command), ButtonBase.CommandProperty, BindingMode.OneWay); } } Bind(source, element, nameof(FontFamily), FontFamilyProperty, BindingMode.OneWay); Bind(source, element, nameof(FontSize), FontSizeProperty, BindingMode.OneWay); Bind(source, element, nameof(FontStretch), FontStretchProperty, BindingMode.OneWay); Bind(source, element, nameof(FontStyle), FontStyleProperty, BindingMode.OneWay); Bind(source, element, nameof(FontWeight), FontWeightProperty, BindingMode.OneWay); Bind(source, element, nameof(Foreground), ForegroundProperty, BindingMode.OneWay); Bind(source, element, nameof(IsEnabled), IsEnabledProperty, BindingMode.OneWay); Bind(source, element, nameof(Opacity), OpacityProperty, BindingMode.OneWay); Bind(source, element, nameof(SnapsToDevicePixels), SnapsToDevicePixelsProperty, BindingMode.OneWay); Bind(source, element, new PropertyPath(FocusManager.IsFocusScopeProperty), FocusManager.IsFocusScopeProperty, BindingMode.OneWay); if (source is IHeaderedControl headeredControl) { if (headeredControl is HeaderedItemsControl) { Bind(source, element, nameof(HeaderedItemsControl.Header), HeaderedItemsControl.HeaderProperty, BindingMode.OneWay); Bind(source, element, nameof(HeaderedItemsControl.HeaderStringFormat), HeaderedItemsControl.HeaderStringFormatProperty, BindingMode.OneWay); Bind(source, element, nameof(HeaderedItemsControl.HeaderTemplate), HeaderedItemsControl.HeaderTemplateProperty, BindingMode.OneWay); Bind(source, element, nameof(HeaderedItemsControl.HeaderTemplateSelector), HeaderedItemsControl.HeaderTemplateSelectorProperty, BindingMode.OneWay); } else { Bind(source, element, nameof(IHeaderedControl.Header), HeaderProperty, BindingMode.OneWay); } if (source.ToolTip != null || BindingOperations.IsDataBound(source, ToolTipProperty)) { Bind(source, element, nameof(ToolTip), ToolTipProperty, BindingMode.OneWay); } else { Bind(source, element, nameof(IHeaderedControl.Header), ToolTipProperty, BindingMode.OneWay); } } var ribbonControl = source as IRibbonControl; if (ribbonControl?.Icon != null) { if (ribbonControl.Icon is Visual iconVisual) { var rect = new Rectangle { Width = 16, Height = 16, Fill = new VisualBrush(iconVisual) }; ((IRibbonControl)element).Icon = rect; } else { Bind(source, element, nameof(IRibbonControl.Icon), IconProperty, BindingMode.OneWay); } } RibbonProperties.SetSize(element, RibbonControlSize.Small); }
private void UpdateKeyTipPositions() { this.Log("UpdateKeyTipPositions"); if (this.keyTips.Count == 0) { return; } double[] rows = null; var groupBox = GetGroupBox(this.oneOfAssociatedElements); if (groupBox != null) { var panel = groupBox.GetPanel(); if (panel != null) { var height = groupBox.GetLayoutRoot().DesiredSize.Height; rows = new[] { groupBox.GetLayoutRoot().TranslatePoint(new Point(0, 0), this.AdornedElement).Y, groupBox.GetLayoutRoot().TranslatePoint(new Point(0, panel.DesiredSize.Height / 2.0), this.AdornedElement).Y, groupBox.GetLayoutRoot().TranslatePoint(new Point(0, panel.DesiredSize.Height), this.AdornedElement).Y, groupBox.GetLayoutRoot().TranslatePoint(new Point(0, height + 1), this.AdornedElement).Y }; } } for (var i = 0; i < this.keyTips.Count; i++) { // Skip invisible keytips if (this.keyTips[i].Visibility != Visibility.Visible) { continue; } // Update KeyTip Visibility var associatedElementIsVisible = this.associatedElements[i].IsVisible; var associatedElementInVisualTree = VisualTreeHelper.GetParent(this.associatedElements[i]) != null; this.keyTips[i].Visibility = associatedElementIsVisible && associatedElementInVisualTree ? Visibility.Visible : Visibility.Collapsed; if (!KeyTip.GetAutoPlacement(this.associatedElements[i])) { #region Custom Placement var keyTipSize = this.keyTips[i].DesiredSize; var elementSize = this.associatedElements[i].RenderSize; double x = 0, y = 0; var margin = KeyTip.GetMargin(this.associatedElements[i]); switch (KeyTip.GetHorizontalAlignment(this.associatedElements[i])) { case HorizontalAlignment.Left: x = margin.Left; break; case HorizontalAlignment.Right: x = elementSize.Width - keyTipSize.Width - margin.Right; break; case HorizontalAlignment.Center: case HorizontalAlignment.Stretch: x = elementSize.Width / 2.0 - keyTipSize.Width / 2.0 + margin.Left; break; } switch (KeyTip.GetVerticalAlignment(this.associatedElements[i])) { case VerticalAlignment.Top: y = margin.Top; break; case VerticalAlignment.Bottom: y = elementSize.Height - keyTipSize.Height - margin.Bottom; break; case VerticalAlignment.Center: case VerticalAlignment.Stretch: y = elementSize.Height / 2.0 - keyTipSize.Height / 2.0 + margin.Top; break; } this.keyTipPositions[i] = this.associatedElements[i].TranslatePoint(new Point(x, y), this.AdornedElement); #endregion } else if (((FrameworkElement)this.associatedElements[i]).Name == "PART_DialogLauncherButton") { // Dialog Launcher Button Exclusive Placement var keyTipSize = this.keyTips[i].DesiredSize; var elementSize = this.associatedElements[i].RenderSize; if (rows == null) { continue; } this.keyTipPositions[i] = this.associatedElements[i].TranslatePoint(new Point( elementSize.Width / 2.0 - keyTipSize.Width / 2.0, 0), this.AdornedElement); this.keyTipPositions[i].Y = rows[3]; } else if ((this.associatedElements[i] is InRibbonGallery && !((InRibbonGallery)this.associatedElements[i]).IsCollapsed)) { // InRibbonGallery Exclusive Placement var keyTipSize = this.keyTips[i].DesiredSize; var elementSize = this.associatedElements[i].RenderSize; if (rows == null) { continue; } this.keyTipPositions[i] = this.associatedElements[i].TranslatePoint(new Point( elementSize.Width - keyTipSize.Width / 2.0, 0), this.AdornedElement); this.keyTipPositions[i].Y = rows[2] - keyTipSize.Height / 2; } else if ((this.associatedElements[i] is RibbonTabItem) || (this.associatedElements[i] is Backstage)) { // Ribbon Tab Item Exclusive Placement var keyTipSize = this.keyTips[i].DesiredSize; var elementSize = this.associatedElements[i].RenderSize; this.keyTipPositions[i] = this.associatedElements[i].TranslatePoint(new Point( elementSize.Width / 2.0 - keyTipSize.Width / 2.0, elementSize.Height - keyTipSize.Height / 2.0), this.AdornedElement); } else if (this.associatedElements[i] is RibbonGroupBox) { // Ribbon Group Box Exclusive Placement var keyTipSize = this.keyTips[i].DesiredSize; var elementSize = this.associatedElements[i].DesiredSize; this.keyTipPositions[i] = this.associatedElements[i].TranslatePoint(new Point( elementSize.Width / 2.0 - keyTipSize.Width / 2.0, elementSize.Height + 1), this.AdornedElement); } else if (IsWithinQuickAccessToolbar(this.associatedElements[i])) { var translatedPoint = this.associatedElements[i].TranslatePoint(new Point(this.associatedElements[i].DesiredSize.Width / 2.0 - this.keyTips[i].DesiredSize.Width / 2.0, this.associatedElements[i].DesiredSize.Height - this.keyTips[i].DesiredSize.Height / 2.0), this.AdornedElement); this.keyTipPositions[i] = translatedPoint; } else if (this.associatedElements[i] is MenuItem) { // MenuItem Exclusive Placement var keyTipSize = this.keyTips[i].DesiredSize; var elementSize = this.associatedElements[i].DesiredSize; this.keyTipPositions[i] = this.associatedElements[i].TranslatePoint( new Point( elementSize.Height / 2.0 + 2, elementSize.Height / 2.0 + 2), this.AdornedElement); } else if (this.associatedElements[i] is BackstageTabItem) { // BackstageButton Exclusive Placement var keyTipSize = this.keyTips[i].DesiredSize; var elementSize = this.associatedElements[i].DesiredSize; this.keyTipPositions[i] = this.associatedElements[i].TranslatePoint( new Point( 5, elementSize.Height / 2.0 - keyTipSize.Height), this.AdornedElement); } else if (((FrameworkElement)this.associatedElements[i]).Parent is BackstageTabControl) { // Backstage Items Exclusive Placement var keyTipSize = this.keyTips[i].DesiredSize; var elementSize = this.associatedElements[i].DesiredSize; this.keyTipPositions[i] = this.associatedElements[i].TranslatePoint( new Point( 20, elementSize.Height / 2.0 - keyTipSize.Height), this.AdornedElement); } else { if ((RibbonProperties.GetSize(this.associatedElements[i]) != RibbonControlSize.Large) || (this.associatedElements[i] is Spinner) || (this.associatedElements[i] is ComboBox) || (this.associatedElements[i] is TextBox) || (this.associatedElements[i] is CheckBox)) { var withinRibbonToolbar = IsWithinRibbonToolbarInTwoLine(this.associatedElements[i]); var translatedPoint = this.associatedElements[i].TranslatePoint(new Point(this.keyTips[i].DesiredSize.Width / 2.0, this.keyTips[i].DesiredSize.Height / 2.0), this.AdornedElement); // Snapping to rows if it present if (rows != null) { var index = 0; var mindistance = Math.Abs(rows[0] - translatedPoint.Y); for (var j = 1; j < rows.Length; j++) { if (withinRibbonToolbar && j == 1) { continue; } var distance = Math.Abs(rows[j] - translatedPoint.Y); if (distance < mindistance) { mindistance = distance; index = j; } } translatedPoint.Y = rows[index] - this.keyTips[i].DesiredSize.Height / 2.0; } this.keyTipPositions[i] = translatedPoint; } else { var translatedPoint = this.associatedElements[i].TranslatePoint(new Point(this.associatedElements[i].DesiredSize.Width / 2.0 - this.keyTips[i].DesiredSize.Width / 2.0, this.associatedElements[i].DesiredSize.Height - 8), this.AdornedElement); if (rows != null) { translatedPoint.Y = rows[2] - this.keyTips[i].DesiredSize.Height / 2.0; } this.keyTipPositions[i] = translatedPoint; } } } }
private void HandleIconMouseDown(object sender, MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.Left) { if (e.ClickCount == 1) { e.Handled = true; ShowSystemMenuPhysicalCoordinates(this, this.PointToScreen(new Point(0, RibbonProperties.GetTitleBarHeight(this)))); } else if (e.ClickCount == 2) { e.Handled = true; this.Close(); } } else if (e.ChangedButton == MouseButton.Right) { e.Handled = true; this.RunInDispatcherAsync(() => { var mousePosition = e.GetPosition(this); ShowSystemMenuPhysicalCoordinates(this, this.PointToScreen(mousePosition)); }); } }
private void UpdateKeyTipPositions() { this.LogDebug("UpdateKeyTipPositions"); if (this.keyTipInformations.Count == 0) { return; } double[] rows = null; var groupBox = this.oneOfAssociatedElements as RibbonGroupBox ?? UIHelper.GetParent <RibbonGroupBox>(this.oneOfAssociatedElements); var panel = groupBox?.GetPanel(); if (panel != null) { var height = groupBox.GetLayoutRoot().DesiredSize.Height; rows = new[] { groupBox.GetLayoutRoot().TranslatePoint(new Point(0, 0), this.AdornedElement).Y, groupBox.GetLayoutRoot().TranslatePoint(new Point(0, panel.DesiredSize.Height / 2.0), this.AdornedElement).Y, groupBox.GetLayoutRoot().TranslatePoint(new Point(0, panel.DesiredSize.Height), this.AdornedElement).Y, groupBox.GetLayoutRoot().TranslatePoint(new Point(0, height + 1), this.AdornedElement).Y }; } foreach (var keyTipInformation in this.keyTipInformations) { // Skip invisible keytips if (keyTipInformation.Visibility != Visibility.Visible) { continue; } // Update KeyTip Visibility var visualTargetIsVisible = keyTipInformation.VisualTarget.IsVisible; var visualTargetInVisualTree = VisualTreeHelper.GetParent(keyTipInformation.VisualTarget) != null; keyTipInformation.Visibility = visualTargetIsVisible && visualTargetInVisualTree ? Visibility.Visible : Visibility.Collapsed; keyTipInformation.KeyTip.Margin = KeyTip.GetMargin(keyTipInformation.AssociatedElement); if (IsWithinQuickAccessToolbar(keyTipInformation.AssociatedElement)) { var x = (keyTipInformation.VisualTarget.DesiredSize.Width / 2.0) - (keyTipInformation.KeyTip.DesiredSize.Width / 2.0); var y = keyTipInformation.VisualTarget.DesiredSize.Height - (keyTipInformation.KeyTip.DesiredSize.Height / 2.0); if (KeyTip.GetAutoPlacement(keyTipInformation.AssociatedElement) == false) { switch (KeyTip.GetHorizontalAlignment(keyTipInformation.AssociatedElement)) { case HorizontalAlignment.Left: x = 0; break; case HorizontalAlignment.Right: x = keyTipInformation.VisualTarget.DesiredSize.Width - keyTipInformation.KeyTip.DesiredSize.Width; break; } } keyTipInformation.Position = keyTipInformation.VisualTarget.TranslatePoint(new Point(x, y), this.AdornedElement); } else if (keyTipInformation.AssociatedElement.Name == "PART_DialogLauncherButton") { // Dialog Launcher Button Exclusive Placement var keyTipSize = keyTipInformation.KeyTip.DesiredSize; var elementSize = keyTipInformation.VisualTarget.RenderSize; if (rows == null) { continue; } keyTipInformation.Position = keyTipInformation.VisualTarget.TranslatePoint(new Point( (elementSize.Width / 2.0) - (keyTipSize.Width / 2.0), 0), this.AdornedElement); keyTipInformation.Position = new Point(keyTipInformation.Position.X, rows[3]); } else if (KeyTip.GetAutoPlacement(keyTipInformation.AssociatedElement) == false) { var keyTipSize = keyTipInformation.KeyTip.DesiredSize; var elementSize = keyTipInformation.VisualTarget.RenderSize; double x = 0, y = 0; switch (KeyTip.GetHorizontalAlignment(keyTipInformation.AssociatedElement)) { case HorizontalAlignment.Left: break; case HorizontalAlignment.Right: x = elementSize.Width - keyTipSize.Width; break; case HorizontalAlignment.Center: case HorizontalAlignment.Stretch: x = (elementSize.Width / 2.0) - (keyTipSize.Width / 2.0); break; } switch (KeyTip.GetVerticalAlignment(keyTipInformation.AssociatedElement)) { case VerticalAlignment.Top: break; case VerticalAlignment.Bottom: y = elementSize.Height - keyTipSize.Height; break; case VerticalAlignment.Center: case VerticalAlignment.Stretch: y = (elementSize.Height / 2.0) - (keyTipSize.Height / 2.0); break; } keyTipInformation.Position = keyTipInformation.VisualTarget.TranslatePoint(new Point(x, y), this.AdornedElement); } else if (keyTipInformation.AssociatedElement is InRibbonGallery && !((InRibbonGallery)keyTipInformation.AssociatedElement).IsCollapsed) { // InRibbonGallery Exclusive Placement var keyTipSize = keyTipInformation.KeyTip.DesiredSize; var elementSize = keyTipInformation.VisualTarget.RenderSize; if (rows == null) { continue; } keyTipInformation.Position = keyTipInformation.VisualTarget.TranslatePoint(new Point( elementSize.Width - (keyTipSize.Width / 2.0), 0), this.AdornedElement); keyTipInformation.Position = new Point(keyTipInformation.Position.X, rows[2] - (keyTipSize.Height / 2)); } else if (keyTipInformation.AssociatedElement is RibbonTabItem || keyTipInformation.AssociatedElement is Backstage) { // Ribbon Tab Item Exclusive Placement var keyTipSize = keyTipInformation.KeyTip.DesiredSize; var elementSize = keyTipInformation.VisualTarget.RenderSize; keyTipInformation.Position = keyTipInformation.VisualTarget.TranslatePoint(new Point( (elementSize.Width / 2.0) - (keyTipSize.Width / 2.0), elementSize.Height - (keyTipSize.Height / 2.0)), this.AdornedElement); } else if (keyTipInformation.AssociatedElement is MenuItem) { // MenuItem Exclusive Placement var elementSize = keyTipInformation.VisualTarget.DesiredSize; keyTipInformation.Position = keyTipInformation.VisualTarget.TranslatePoint( new Point( (elementSize.Height / 3.0) + 2, (elementSize.Height / 4.0) + 2), this.AdornedElement); } else if (keyTipInformation.AssociatedElement.Parent is BackstageTabControl) { // Backstage Items Exclusive Placement var keyTipSize = keyTipInformation.KeyTip.DesiredSize; var elementSize = keyTipInformation.VisualTarget.DesiredSize; var parent = (UIElement)keyTipInformation.VisualTarget.Parent; var positionInParent = keyTipInformation.VisualTarget.TranslatePoint(default(Point), parent); keyTipInformation.Position = parent.TranslatePoint( new Point( 5, positionInParent.Y + ((elementSize.Height / 2.0) - keyTipSize.Height)), this.AdornedElement); } else { if (RibbonProperties.GetSize(keyTipInformation.AssociatedElement) != RibbonControlSize.Large || IsTextBoxShapedControl(keyTipInformation.AssociatedElement)) { var withinRibbonToolbar = IsWithinRibbonToolbarInTwoLine(keyTipInformation.VisualTarget); var x = keyTipInformation.KeyTip.DesiredSize.Width / 2.0; var y = keyTipInformation.KeyTip.DesiredSize.Height / 2.0; var point = new Point(x, y); var translatedPoint = keyTipInformation.VisualTarget.TranslatePoint(point, this.AdornedElement); // Snapping to rows if it present if (rows != null) { var index = 0; var mindistance = Math.Abs(rows[0] - translatedPoint.Y); for (var j = 1; j < rows.Length; j++) { if (withinRibbonToolbar && j == 1) { continue; } var distance = Math.Abs(rows[j] - translatedPoint.Y); if (distance < mindistance) { mindistance = distance; index = j; } } translatedPoint.Y = rows[index] - (keyTipInformation.KeyTip.DesiredSize.Height / 2.0); } keyTipInformation.Position = translatedPoint; } else { var x = (keyTipInformation.VisualTarget.DesiredSize.Width / 2.0) - (keyTipInformation.KeyTip.DesiredSize.Width / 2.0); var y = keyTipInformation.VisualTarget.DesiredSize.Height - 8; var point = new Point(x, y); var translatedPoint = keyTipInformation.VisualTarget.TranslatePoint(point, this.AdornedElement); if (rows != null) { translatedPoint.Y = rows[2] - (keyTipInformation.KeyTip.DesiredSize.Height / 2.0); } keyTipInformation.Position = translatedPoint; } } } }
/// <summary> /// Binds default properties of control to quick access element /// </summary> /// <param name="element">Toolbar item</param> /// <param name="source">Source item</param> public static void BindQuickAccessItem(FrameworkElement source, FrameworkElement element) { Bind(source, element, "DataContext", DataContextProperty, BindingMode.OneWay); if (source is ICommandSource) { if (source is MenuItem) { Bind(source, element, "CommandParameter", ButtonBase.CommandParameterProperty, BindingMode.OneWay); Bind(source, element, "CommandTarget", System.Windows.Controls.MenuItem.CommandTargetProperty, BindingMode.OneWay); Bind(source, element, "Command", System.Windows.Controls.MenuItem.CommandProperty, BindingMode.OneWay); } else { Bind(source, element, "CommandParameter", ButtonBase.CommandParameterProperty, BindingMode.OneWay); Bind(source, element, "CommandTarget", ButtonBase.CommandTargetProperty, BindingMode.OneWay); Bind(source, element, "Command", ButtonBase.CommandProperty, BindingMode.OneWay); } } Bind(source, element, "ToolTip", ToolTipProperty, BindingMode.OneWay); Bind(source, element, "FontFamily", FontFamilyProperty, BindingMode.OneWay); Bind(source, element, "FontSize", FontSizeProperty, BindingMode.OneWay); Bind(source, element, "FontStretch", FontStretchProperty, BindingMode.OneWay); Bind(source, element, "FontStyle", FontStyleProperty, BindingMode.OneWay); Bind(source, element, "FontWeight", FontWeightProperty, BindingMode.OneWay); Bind(source, element, "Foreground", ForegroundProperty, BindingMode.OneWay); Bind(source, element, "IsEnabled", IsEnabledProperty, BindingMode.OneWay); Bind(source, element, "Opacity", OpacityProperty, BindingMode.OneWay); Bind(source, element, "SnapsToDevicePixels", SnapsToDevicePixelsProperty, BindingMode.OneWay); Bind(source, element, new PropertyPath(FocusManager.IsFocusScopeProperty), FocusManager.IsFocusScopeProperty, BindingMode.OneWay); var sourceControl = source as IRibbonControl; if (sourceControl != null) { if (sourceControl.Icon != null) { var iconVisual = sourceControl.Icon as Visual; if (iconVisual != null) { var rect = new Rectangle(); rect.Width = 16; rect.Height = 16; rect.Fill = new VisualBrush(iconVisual); ((IRibbonControl)element).Icon = rect; } else { Bind(source, element, "Icon", IconProperty, BindingMode.OneWay); } } if (sourceControl.Header != null) { Bind(source, element, "Header", HeaderProperty, BindingMode.OneWay); } } RibbonProperties.SetSize(element, RibbonControlSize.Small); }
// Size change to collapse ribbon private void OnSizeChanged(object sender, SizeChangedEventArgs e) { this.MaintainIsCollapsed(); if (this.iconImage is not null && this.ActualWidth <= 140D + RibbonProperties.GetLastVisibleWidth(this.iconImage).GetZeroIfInfinityOrNaN() + RibbonProperties.GetLastVisibleWidth(this.WindowCommands?.ItemsControl).GetZeroIfInfinityOrNaN()) { this.SetCurrentValue(IsIconVisibleProperty, BooleanBoxes.FalseBox); this.TitleBar?.SetCurrentValue(VisibilityProperty, VisibilityBoxes.Collapsed); this.WindowCommands?.SetCurrentValue(WindowCommands.ItemsPanelVisibilityProperty, VisibilityBoxes.Collapsed); }
/// <summary> /// Layout logic for the given layout definition /// </summary> /// <param name="layoutDefinition">Current layout definition</param> /// <param name="availableSize">Available or final size</param> /// <param name="measure">Pass true if measure required; pass false if arrange required</param> /// <param name="addchildren">Determines whether we have to add children to the logical and visual tree</param> /// <returns>Final size</returns> private Size CustomLayout(RibbonToolBarLayoutDefinition layoutDefinition, Size availableSize, bool measure, bool addchildren) { var arrange = !measure; var availableHeight = double.IsPositiveInfinity(availableSize.Height) ? 0 : availableSize.Height; // Clear separator cahce if (addchildren) { this.separatorCache.Clear(); } // Get the first control and measure, its height accepts as row height var rowHeight = this.GetRowHeight(layoutDefinition); // Calculate whitespace var rowCountInColumn = Math.Min(layoutDefinition.RowCount, layoutDefinition.Rows.Count); var whitespace = (availableHeight - (rowCountInColumn * rowHeight)) / (rowCountInColumn + 1); double y = 0; double currentRowBegin = 0; double currentMaxX = 0; double maxy = 0; for (var rowIndex = 0; rowIndex < layoutDefinition.Rows.Count; rowIndex++) { var row = layoutDefinition.Rows[rowIndex]; var x = currentRowBegin; if (rowIndex % rowCountInColumn == 0) { // Reset vars at new column x = currentRowBegin = currentMaxX; y = 0; if (rowIndex != 0) { #region Add separator if (this.separatorCache.TryGetValue(rowIndex, out var separator) == false) { separator = new Separator { Style = this.SeparatorStyle }; this.separatorCache.Add(rowIndex, separator); } if (measure) { separator.Height = availableHeight - separator.Margin.Bottom - separator.Margin.Top; separator.Measure(availableSize); } if (arrange) { separator.Arrange(new Rect(x, y, separator.DesiredSize.Width, separator.DesiredSize.Height)); } x += separator.DesiredSize.Width; if (addchildren) { // Add control in the children this.AddVisualChild(separator); this.AddLogicalChild(separator); this.actualChildren.Add(separator); } #endregion } } y += whitespace; // Measure & arrange new row for (var i = 0; i < row.Children.Count; i++) { // Control Definition Case if (row.Children[i] is RibbonToolBarControlDefinition ribbonToolBarControlDefinition) { var control = this.GetControl(ribbonToolBarControlDefinition); if (control is null) { continue; } if (addchildren) { // Add control in the children this.AddVisualChild(control); this.AddLogicalChild(control); this.actualChildren.Add(control); } if (measure) { // Apply Control Definition Properties RibbonProperties.SetSize(control, RibbonProperties.GetSize(ribbonToolBarControlDefinition)); control.Width = ribbonToolBarControlDefinition.Width; control.Measure(availableSize); } if (arrange) { control.Arrange(new Rect(x, y, control.DesiredSize.Width, control.DesiredSize.Height)); } x += control.DesiredSize.Width; } // Control Group Definition Case if (row.Children[i] is RibbonToolBarControlGroupDefinition ribbonToolBarControlGroupDefinition) { var control = this.GetControlGroup(ribbonToolBarControlGroupDefinition); if (addchildren) { // Add control in the children this.AddVisualChild(control); this.AddLogicalChild(control); this.actualChildren.Add(control); } if (measure) { // Apply Control Definition Properties control.IsFirstInRow = i == 0; control.IsLastInRow = i == row.Children.Count - 1; control.Measure(availableSize); } if (arrange) { control.Arrange(new Rect(x, y, control.DesiredSize.Width, control.DesiredSize.Height)); } x += control.DesiredSize.Width; } } y += rowHeight; if (currentMaxX < x) { currentMaxX = x; } if (maxy < y) { maxy = y; } } return(new Size(currentMaxX, maxy + whitespace)); }
private void HandleIconMouseDown(object sender, MouseButtonEventArgs e) { switch (e.ChangedButton) { case MouseButton.Left: if (e.ClickCount == 1) { e.Handled = true; WindowSteeringHelper.ShowSystemMenuPhysicalCoordinates(this, e, this.PointToScreen(new Point(0, RibbonProperties.GetTitleBarHeight(this)))); } else if (e.ClickCount == 2) { e.Handled = true; this.Close(); } break; case MouseButton.Right: e.Handled = true; this.RunInDispatcherAsync(() => { WindowSteeringHelper.ShowSystemMenuPhysicalCoordinates(this, e); }); break; } }