Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting a HamburgerMenu.Content is giving a nullexception error #3241

Closed
touyets opened this issue May 5, 2018 · 5 comments · Fixed by #3444
Closed

Setting a HamburgerMenu.Content is giving a nullexception error #3241

touyets opened this issue May 5, 2018 · 5 comments · Fixed by #3444
Labels
Milestone

Comments

@touyets
Copy link

touyets commented May 5, 2018

Sometimes, if i click too fast between the menus on a hamburgermenu, this section of the code behind launches a nullexception error:

private void SplitViewFrame_OnNavigated(object sender, NavigationEventArgs e)
        {
            this.HamburgerMenuControl.Content = e.Content;
}

I have looked at outputs and clicking the menus is delivering the correct outputs with the code below:

private void HamburgerMenuControl_OnItemInvoked(object sender, HamburgerMenuItemInvokedEventArgs e)
        {
            if (e.InvokedItem is MenuItem menuItem && menuItem.IsNavigation)
            {
                Navigation.Navigate(menuItem.NavigationDestination, menuItem);
            }
        }

but the _OnNavigated part marked above will give a null error without me being able to find out why.

UPDATE: It is now happening now every time I try to go a second menu. Meaning: I click on a menu item and it works perfectly and whatever other menu item I click on next gives that null error every time.

@kszabolcs
Copy link

I have experienced the same. And one more thing: _ItemInvoked and _ItemClick will always raise, if I change the selection index with buttons. For example: I set the focus with Tab button to the MenuItems and change the selection with arrow buttons (up and down), then the _ItemInvoked and _ItemClick events will always raised, however I didn't clicked on the button. I think it's a problem too.

@punker76
Copy link
Member

@touyets Please create a simple sample, so I can investigate what's going on there.

@punker76
Copy link
Member

@kszabolcs Why do you think this is a problem?

@kszabolcs
Copy link

I think, the selection and the click event have to be two different event. For example let's say I don't have a mouse (ok, I know this is very extreme, but it's a possible case) and I want to click on the third menu item. Firstly I need to set the focus to the MenuItems with Tab button, then set the selection to the third button with the arrow buttons and when it will be selected then possible to raise the click event with Enter or with Space button.

Currently if I move the selection the Click event will be raised on every selection change, but I want to change the hamburger menu content only on the click event and not on selection.

As I know, every Windows hamburger menu works on this way (for example check the Mail or the Groove Music applications).
Am I wrong? Then sorry.

On the other hand, you can investigate the demo application. There the situation is the same. Check HamburgerMenu_OnItemClick event in HamburgerMenuDefault.xaml.cs file.

@punker76
Copy link
Member

@kszabolcs

Currently if I move the selection the Click event will be raised on every selection change, but I want to change the hamburger menu content only on the click event and not on selection.

This HamburgerMenu uses the normal WPF ListBox which directly selects a ListBoxItem if you use the up/down/left/right keys. If you find a better solution or know a better control then let me know or create a PR to change this behavior.

I know the UWP version for this (now the NavigationView) works different, but until there will be a better control or solution, the current selection/focusing behavior is ok.

To prevent your nullpointer exception I changed a the inner part for the selection/clicked/invoked stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

3 participants