Skip to content

Commit

Permalink
fix exception in menuitem extension
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlm committed Nov 30, 2024
1 parent ad9bc55 commit f320cab
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ 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 f320cab

Please sign in to comment.