question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NavigationViewPaneClosingEventArgs.Cancel = true is not preventing the navigation pane from beeing closed

See original GitHub issue

Describe the bug I want a menu flyout to be opened when clicking on one navigation view item (see #1570). image image

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:

  1. 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);
}
  1. In the PaneClosing event handler use the following code
private void NavigationView_PaneClosing(Mux.NavigationView sender, Mux.NavigationViewPaneClosingEventArgs args)
{
    args.Cancel = _disablePaneAutoClosing;
}
  1. Launch the application and click on the “menu entry” in the navigation pane.
  2. 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:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Felix-Devcommented, Sep 30, 2020

@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.

1reaction
Felix-Devcommented, Sep 30, 2020

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to cancel navigation on validation in UWP XAML ...
1 Answer. It's possible to stop navigation by using the property SelectsOnInvoked on the NavigationViewItem . Setting this to False will stop ...
Read more >
NavigationView Pane does not close after clicking on an item
Describe the bug When the navigationview is in the compact mode and it is expanded using hamburger menu and an item is clicked....
Read more >
FormClosingEventArgs Class (System.Windows.Forms)
The event can be canceled by setting the Cancel property to true. The CloseReason property provides a reason why the form is being...
Read more >
[Solved] FormClosing e.cancel = true not working
The problem is that when the form is closing, it does hit the closing event and set e.cancel to true, but then the...
Read more >
Prevent Users Closing Your Windows Form - Dave on C-Sharp
Sometimes you might require to stop a user from closing your Windows form – maybe because the form ... Cancel = true; and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found