diff --git a/Changelog.md b/Changelog.md index 2ca3e13e0..83db7ec31 100644 --- a/Changelog.md +++ b/Changelog.md @@ -130,6 +130,7 @@ This also overrules the fix made for [#415](../../issues/415). - [#430](../../issues/430) - No Rezising at Fluent:RibbonContextualTabGroup at Version 5.0 - [#438](../../issues/438) - Titlebar icon missing left margin when maximized + - [#439](../../issues/439) - Context menu and submenu disappears after a right click - ### Enhancements - `LayoutTransform` and `RenderTransform` can now be used directly on `RibbonWindow` as this now gets forwarded to the first template child of the window. Have a look at `TestWindow` in the showcase application for an example on how to use it. This was added as the fix for [#430](../../issues/430). diff --git a/Fluent.Ribbon/Controls/MenuItem.cs b/Fluent.Ribbon/Controls/MenuItem.cs index 08a3268e9..a64332b4a 100644 --- a/Fluent.Ribbon/Controls/MenuItem.cs +++ b/Fluent.Ribbon/Controls/MenuItem.cs @@ -21,7 +21,7 @@ namespace Fluent /// Represents menu item /// [ContentProperty(nameof(Items))] - public class MenuItem : System.Windows.Controls.MenuItem, IQuickAccessItemProvider, IRibbonControl + public class MenuItem : System.Windows.Controls.MenuItem, IQuickAccessItemProvider, IRibbonControl, IDropDownControl { #region Fields @@ -498,6 +498,8 @@ public bool CanAddToQuickAccessToolBar /// public static readonly DependencyProperty CanAddToQuickAccessToolBarProperty = RibbonControl.CanAddToQuickAccessToolBarProperty.AddOwner(typeof(MenuItem)); + private bool isContextMenuOpening; + #endregion #region Public @@ -576,6 +578,40 @@ protected override void OnMouseEnter(MouseEventArgs e) } } + /// + protected override void OnMouseLeave(MouseEventArgs e) + { + if (this.isContextMenuOpening) + { + return; + } + + base.OnMouseLeave(e); + } + + /// + protected override void OnContextMenuOpening(ContextMenuEventArgs e) + { + this.isContextMenuOpening = true; + this.IsContextMenuOpened = true; + + base.OnContextMenuOpening(e); + } + + /// + protected override void OnContextMenuClosing(ContextMenuEventArgs e) + { + this.isContextMenuOpening = false; + this.IsContextMenuOpened = false; + + base.OnContextMenuClosing(e); + + if (this.IsMouseOver == false) + { + this.OnMouseLeave(new MouseEventArgs(Mouse.PrimaryDevice, 0)); + } + } + #endregion Non MenuBase ItemsControl workarounds /// @@ -661,17 +697,6 @@ public override void OnApplyTemplate() this.menuPanel = this.GetTemplateChild("PART_MenuPanel") as Panel; } - /// - /// Invoked when an unhandled  attached event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event. - /// - /// The that contains the event data. - protected override void OnPreviewLostKeyboardFocus(KeyboardFocusChangedEventArgs e) - { - Debug.WriteLine("MenuItem focus lost - " + this); - //base.OnPreviewLostKeyboardFocus(e); - //e.Handled = true; - } - /// /// Responds to the event. ///