feat: add new event.
This commit is contained in:
@@ -189,6 +189,16 @@ public class NavMenu : ItemsControl, ICustomKeyboardNavigation
|
||||
add => AddHandler(SelectionChangedEvent, value);
|
||||
remove => RemoveHandler(SelectionChangedEvent, value);
|
||||
}
|
||||
|
||||
|
||||
public static readonly RoutedEvent<SelectionChangedEventArgs> SelectionChangingEvent =
|
||||
RoutedEvent.Register<NavMenu, SelectionChangedEventArgs>(nameof(SelectionChanging), RoutingStrategies.Bubble);
|
||||
|
||||
public event EventHandler SelectionChanging
|
||||
{
|
||||
add => AddHandler(SelectionChangingEvent, value);
|
||||
remove => RemoveHandler(SelectionChangingEvent, value);
|
||||
}
|
||||
|
||||
protected override bool NeedsContainerOverride(object? item, int index, out object? recycleKey)
|
||||
{
|
||||
@@ -486,4 +496,22 @@ public class NavMenu : ItemsControl, ICustomKeyboardNavigation
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
internal bool CanChangeSelection(NavMenuItem item)
|
||||
{
|
||||
object? newSelection = null;
|
||||
if (item.DataContext is not null && item.DataContext != DataContext)
|
||||
newSelection = item.DataContext;
|
||||
else
|
||||
newSelection = item;
|
||||
var args = new SelectionChangingEventArgs(
|
||||
SelectionChangingEvent,
|
||||
new[] { SelectedItem },
|
||||
new[] { newSelection })
|
||||
{
|
||||
Source = this,
|
||||
};
|
||||
RaiseEvent(args);
|
||||
return args.CanSelect;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user