diff --git a/src/Ursa/Controls/NavMenu/NavMenu.cs b/src/Ursa/Controls/NavMenu/NavMenu.cs index dabec9a..bbe036d 100644 --- a/src/Ursa/Controls/NavMenu/NavMenu.cs +++ b/src/Ursa/Controls/NavMenu/NavMenu.cs @@ -191,10 +191,10 @@ public class NavMenu : ItemsControl, ICustomKeyboardNavigation } - public static readonly RoutedEvent SelectionChangingEvent = - RoutedEvent.Register(nameof(SelectionChanging), RoutingStrategies.Bubble); + public static readonly RoutedEvent SelectionChangingEvent = + RoutedEvent.Register(nameof(SelectionChanging), RoutingStrategies.Bubble); - public event EventHandler SelectionChanging + public event EventHandler SelectionChanging { add => AddHandler(SelectionChangingEvent, value); remove => RemoveHandler(SelectionChangingEvent, value); @@ -512,6 +512,12 @@ public class NavMenu : ItemsControl, ICustomKeyboardNavigation Source = this, }; RaiseEvent(args); - return args.CanSelect; + var result = args.CanSelect; + if (result == false) + { + var container = GetContainerForItem(SelectedItem); + container?.Focus(NavigationMethod.Directional); + } + return result; } } \ No newline at end of file diff --git a/src/Ursa/Controls/NavMenu/NavMenuItem.cs b/src/Ursa/Controls/NavMenu/NavMenuItem.cs index 1ba56fb..378cf6c 100644 --- a/src/Ursa/Controls/NavMenu/NavMenuItem.cs +++ b/src/Ursa/Controls/NavMenu/NavMenuItem.cs @@ -381,6 +381,10 @@ public class NavMenuItem : HeaderedItemsControl internal void SelectItem(NavMenuItem item) { + if (item == this && RootMenu?.CanChangeSelection(item) != true) + { + return; + } SetCurrentValue(IsSelectedProperty, item == this); SetCurrentValue(IsHighlightedProperty, true); diff --git a/src/Ursa/Controls/NavMenu/SelectionChangingEventArgs.cs b/src/Ursa/Controls/NavMenu/SelectionChangingEventArgs.cs index 3b5c95b..0e8e448 100644 --- a/src/Ursa/Controls/NavMenu/SelectionChangingEventArgs.cs +++ b/src/Ursa/Controls/NavMenu/SelectionChangingEventArgs.cs @@ -6,19 +6,19 @@ namespace Ursa.Controls; public class SelectionChangingEventArgs: RoutedEventArgs { /// Gets the items that were added to the selection. - public IList AddedItems { get; } + public IList NewItems { get; } /// Gets the items that were removed from the selection. - public IList RemovedItems { get; } + public IList OldItems { get; } /// /// Gets or sets a value indicating whether the selection can be changed. If set to false, the selection will not change. /// public bool CanSelect { get; set; } = true; - public SelectionChangingEventArgs(RoutedEvent routedEvent, IList removedItems, IList addedItems): base(routedEvent) + public SelectionChangingEventArgs(RoutedEvent routedEvent, IList oldItems, IList newItems): base(routedEvent) { - RemovedItems = removedItems; - AddedItems = addedItems; + OldItems = oldItems; + NewItems = newItems; } } \ No newline at end of file