NavigationViewPaneClosingEventArgs.Cancel = true is not preventing the navigation pane from beeing closed
See original GitHub issueDescribe the bug I want a menu flyout to be opened when clicking on one navigation view item (see #1570).
I was planning to use the hierarchical navigation for my scenario but because of #3343, I cannot use it 😥.
I will keep using a regular flyout and was planning to use the NavigationView.PaneClosing
event (and the `NavigationViewPaneClosingEventArgs.Cancel property) to prevent the panel to close while my custom flyout is opened.
Unfortunately, this is not working. The event handler is invoked but the NavigationViewPaneClosingEventArgs.Cancel
value is ignored.
Steps to reproduce the bug Use the following sample application: NavigationViewClosingEvent.zip Steps to reproduce the behavior:
- In the
ItemInvoked
event handler use the following code:
if (args.InvokedItemContainer == menuEntry)
{
var flyout = FlyoutBase.GetAttachedFlyout(menuEntry);
flyout.Closed += Flyout_Closed;
_disablePaneAutoClosing = true;
flyout.ShowAt(menuEntry);
}
- In the
PaneClosing
event handler use the following code
private void NavigationView_PaneClosing(Mux.NavigationView sender, Mux.NavigationViewPaneClosingEventArgs args)
{
args.Cancel = _disablePaneAutoClosing;
}
- Launch the application and click on the “menu entry” in the navigation pane.
- The menu flyout is displayed
Expected behavior
The navigation pane remains open when NavigationViewPaneClosingEventArgs.Cancel
is set to true.
Actual behavior The navigation pane is closing.
Additional context
I tried to handle the SplitView.PaneClosing
event from the inner SPlitView
but it is also not working.
private void NavigationView_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
var splitview = ((FrameworkElement)sender).FindDescendant<SplitView>();
splitview.PaneClosing += Splitview_PaneClosing;
}
private void Splitview_PaneClosing(SplitView sender, SplitViewPaneClosingEventArgs args)
{
args.Cancel = _disablePaneAutoClosing;
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
@StephenLPeters I would like to look into this bug then. I will also create a Feature Proposal for the
Reason
API which can then be used for further discussions.This looks like a bug to me. I can cancel the pane closing when in the LeftCompact/LeftMinimal modes and click elsewhere on the app surface (i.e. light dismiss behavior), yet I cannot prevent the pane from closing when selecting a menu item. Since this API exists, I would expect it to be respected in such a case as well.
Seeing this specific example, just throwing out a thought: Should we consider extending the NavigationViewPaneClosingEventArgs API to have a
Reason
API which states the reason for the pane close? I.e. light-dismissed (clicking elsewhere on the app surface), item invoked,…That way @vgromfeld wouldn’t have to use a custom flag like_disablePaneAutoClosing
here. I’m not sure if enough demand exists justifying adding an API for that though…just looking at this repo, it appears not (and the non-existence of that API wouldn’t block @vgromfeld anyway).@StephenLPeters @YuliKl What do you think?