Skip to content

Commit

Permalink
Fixing problems with eager closing when the context menu is used
Browse files Browse the repository at this point in the history
  • Loading branch information
batzen committed Aug 25, 2018
1 parent c5f8820 commit 229de24
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions Fluent.Ribbon/Controls/MenuItem.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -444,14 +440,10 @@ protected override void OnMouseEnter(MouseEventArgs e)
/// <inheritdoc />
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
Expand All @@ -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);
}
Expand All @@ -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
Expand Down

0 comments on commit 229de24

Please sign in to comment.