Skip to content

Commit

Permalink
fix exception in menuitem extension (#156)
Browse files Browse the repository at this point in the history
* fix exception in menuitem extension
  • Loading branch information
tomlm authored Nov 30, 2024
1 parent 13e2b54 commit 7f76b39
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ static MenuExtensions()
var focusedControl =
(Control)AvaloniaLocator.Current.GetRequiredService<IFocusManager>()!
.GetFocusedElement();
var menuItems = visual.GetLogicalAncestors().OfType<MenuItem>();

var focusedTree = focusedControl!.GetLogicalAncestors();
if (focusedControl != null)
{
var focusedTree = focusedControl.GetLogicalAncestors();
var menuItems = visual.GetLogicalAncestors().OfType<MenuItem>();

foreach (MenuItem menuItem in menuItems.Where(item => !focusedTree.Contains(item))
.ToArray())
menuItem.Close();
foreach (MenuItem menuItem in menuItems
.Where(item => !focusedTree.Contains(item))
.ToArray())
menuItem.Close();
}
});
}));
visual.SetValue(DisposablesProperty, new[] { disposable });
Expand Down

0 comments on commit 7f76b39

Please sign in to comment.