diff --git a/Changelog.md b/Changelog.md index 8eea2be51..2bc5ff95a 100644 --- a/Changelog.md +++ b/Changelog.md @@ -46,6 +46,7 @@ - [#552](../../issues/552) - RibbonGroupBox should resize when font family or size are changed - [#562](../../issues/562) - Pressing "right" arrow key to open submenu on menuitem causes NullRef exception when there is no submenu - [#564](../../issues/564) - Gallery overflow panel (with menu items) doesn't close when clicking once in the application + - [#572](../../issues/572) - KeyTip.Keys Position - ### Enhancements - [#516](../../issues/516) - Add options to hide the row containing RibbonTabItems diff --git a/Fluent.Ribbon/Adorners/KeyTipAdorner.cs b/Fluent.Ribbon/Adorners/KeyTipAdorner.cs index 7a39e5d10..e30534667 100644 --- a/Fluent.Ribbon/Adorners/KeyTipAdorner.cs +++ b/Fluent.Ribbon/Adorners/KeyTipAdorner.cs @@ -715,35 +715,13 @@ private void UpdateKeyTipPositions() 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); - } + SnapToRowsIfPresent(rows, keyTipInformation, translatedPoint); keyTipInformation.Position = translatedPoint; } @@ -754,10 +732,8 @@ private void UpdateKeyTipPositions() 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); - } + // Snapping to rows if it present + SnapToRowsIfPresent(rows, keyTipInformation, translatedPoint); keyTipInformation.Position = translatedPoint; } @@ -796,6 +772,35 @@ private static bool IsWithinQuickAccessToolbar(DependencyObject element) return UIHelper.GetParent(element) != null; } + private static void SnapToRowsIfPresent(double[] rows, KeyTipInformation keyTipInformation, Point translatedPoint) + { + if (rows == null) + { + return; + } + + var withinRibbonToolbar = IsWithinRibbonToolbarInTwoLine(keyTipInformation.VisualTarget); + + 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); + } + /// protected override int VisualChildrenCount => this.keyTipInformations.Count;