Skip to content

Commit

Permalink
Fixes #439 by taking counter measures against inherited behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
batzen committed Jun 16, 2017
1 parent 72c1971 commit abb926d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
49 changes: 37 additions & 12 deletions Fluent.Ribbon/Controls/MenuItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Fluent
/// Represents menu item
/// </summary>
[ContentProperty(nameof(Items))]
public class MenuItem : System.Windows.Controls.MenuItem, IQuickAccessItemProvider, IRibbonControl
public class MenuItem : System.Windows.Controls.MenuItem, IQuickAccessItemProvider, IRibbonControl, IDropDownControl
{
#region Fields

Expand Down Expand Up @@ -498,6 +498,8 @@ public bool CanAddToQuickAccessToolBar
/// </summary>
public static readonly DependencyProperty CanAddToQuickAccessToolBarProperty = RibbonControl.CanAddToQuickAccessToolBarProperty.AddOwner(typeof(MenuItem));

private bool isContextMenuOpening;

#endregion

#region Public
Expand Down Expand Up @@ -576,6 +578,40 @@ protected override void OnMouseEnter(MouseEventArgs e)
}
}

/// <inheritdoc />
protected override void OnMouseLeave(MouseEventArgs e)
{
if (this.isContextMenuOpening)
{
return;
}

base.OnMouseLeave(e);
}

/// <inheritdoc />
protected override void OnContextMenuOpening(ContextMenuEventArgs e)
{
this.isContextMenuOpening = true;
this.IsContextMenuOpened = true;

base.OnContextMenuOpening(e);
}

/// <inheritdoc />
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

/// <summary>
Expand Down Expand Up @@ -661,17 +697,6 @@ public override void OnApplyTemplate()
this.menuPanel = this.GetTemplateChild("PART_MenuPanel") as Panel;
}

/// <summary>
/// Invoked when an unhandled <see cref="E:System.Windows.Input.Keyboard.PreviewKeyDown"/> attached event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event.
/// </summary>
/// <param name="e">The <see cref="T:System.Windows.Input.KeyboardFocusChangedEventArgs"/> that contains the event data.</param>
protected override void OnPreviewLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
{
Debug.WriteLine("MenuItem focus lost - " + this);
//base.OnPreviewLostKeyboardFocus(e);
//e.Handled = true;
}

/// <summary>
/// Responds to the <see cref="E:System.Windows.UIElement.KeyDown"/> event.
/// </summary>
Expand Down

0 comments on commit abb926d

Please sign in to comment.