diff --git a/Fluent.Ribbon/Controls/MenuItem.cs b/Fluent.Ribbon/Controls/MenuItem.cs index 463356924..bcb82ed11 100644 --- a/Fluent.Ribbon/Controls/MenuItem.cs +++ b/Fluent.Ribbon/Controls/MenuItem.cs @@ -1,8 +1,7 @@ -// ReSharper disable once CheckNamespace +// ReSharper disable once CheckNamespace namespace Fluent { using System; - using System.Reflection; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; @@ -23,10 +22,6 @@ public class MenuItem : System.Windows.Controls.MenuItem, IQuickAccessItemProvid { #region Fields - //DependencyPropertyKey - private static readonly FieldInfo rolePropertyKeyFieldInfo = typeof(System.Windows.Controls.MenuItem).GetField("RolePropertyKey", BindingFlags.Static | BindingFlags.NonPublic); - private static readonly DependencyPropertyKey rolePropertyKey = (DependencyPropertyKey)rolePropertyKeyFieldInfo.GetValue(null); - // Thumb to resize in both directions private Thumb resizeBothThumb; // Thumb to resize vertical @@ -431,7 +426,8 @@ protected override void OnMouseEnter(MouseEventArgs e) { base.OnMouseEnter(e); - if (this.IsItemsControlMenuBase == false) + if (this.IsItemsControlMenuBase == false + && this.isContextMenuOpening == false) { if (this.HasItems && this.Parent is DropDownButton) @@ -444,14 +440,10 @@ protected override void OnMouseEnter(MouseEventArgs e) /// protected override void OnMouseLeave(MouseEventArgs e) { - if (this.isContextMenuOpening) - { - return; - } - base.OnMouseLeave(e); - if (this.IsItemsControlMenuBase == false) + if (this.IsItemsControlMenuBase == false + && this.isContextMenuOpening == false) { if (this.HasItems && this.Parent is DropDownButton // prevent too slow close on regular DropDown @@ -466,7 +458,13 @@ protected override void OnMouseLeave(MouseEventArgs e) protected override void OnContextMenuOpening(ContextMenuEventArgs e) { this.isContextMenuOpening = true; - this.IsContextMenuOpened = true; + + // We have to close the sub menu as soon as the context menu gets opened + // but only if it should be opened on ourself + if (ReferenceEquals(this, e.Source)) + { + this.IsSubmenuOpen = false; + } base.OnContextMenuOpening(e); } @@ -475,14 +473,8 @@ protected override void OnContextMenuOpening(ContextMenuEventArgs 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