Hamburger Menu doesn't stay open on first click
Using the Template 10 (Minimal) project, the Hamburger Menu will not stay open the first time you click it. It will open and close instantly, next time you click the Hamburger Menu it stays open as it's supposed to.
Edit: Forgot to mention that this only applies to VisualStateNarrow.
Do you have any ideas on why this is occurring? Have you looked @ the class?
I have seen this in my project. I think what is happening is you open the app and click the hamburger button but then some background task finishes and hops on the UI thread to update it. This causes the hamburger menu to close.
If I open the app and wait till my process finishes it doesn't close on first open.
No I haven't looked at the class, I'm a bit of a rookie just trying to learn c#. But it's very easy to reproduce, just create a new project based on the Minimal template, launch the app and make sure it's narrow, then click Hamburger Menu button.
Contrary to ajmcateer, it doesn't matter how long I wait, it will always close the first time I open it.
This problem occurs in BottomAppBar sample. After update Shell.xaml in BottomAppBar like in Minimal Template works HamburgerMenu normally.
It works abnormally in the Minimal template also. The problem is, the NavButton_Loaded event is raised when you open the menu for the first time if it is in the Narrow visual state. I assume this is because the NavButtons are completely hidden in that visual state until you open the menu. One thing that happens when the NavButton loads for the first time is the SetSelected method is called, and in line 390 (HamburgerMenu.xaml.cs), we see: IsOpen = false;
This is what is causing the issue, @JerryNixon.
I believe my theory is also supported by the fact that the problem doesn't occur if the app is in any other visual state before opening the HamburgerMenu (so it only happens if the app launches into the Narrow visual state because then you never see the NavButtons). It seems like the best way to get around this is to make sure that the buttons have been loaded before the user interacts with them, so as a workaround, you can quickly open and close the menu when you first navigate to the page.
I should add, this only happens if HamburgerMenu.AutoHighlightCorrectButton == true.
I have an idea to fix this in a way that I'm not too crazy about.
private bool _navButtonsLoaded = false;
void NavButton_Loaded(...)
{
...
HighlightCorrectButton();
_navButtonsLoaded = true;
}
Then in SetSelected:
private void SetSelected(HamburgerButtonInfo previous, HamburgerButtonInfo value)
{
if (_navButtonsLoaded) { IsOpen = false; }
...
}
The issue still exists, BTW. I compiled the sources just yet and when the app starts up in narrow mode, the hamburgermenu opens immediately - and then closes (animated, translating to the left).
I also faced the bug. Could you provide reliable fix? I use Template10 for comercial project...
Whew! Fixed it. Crazy. Had to add this if statement regarding previous.
private void SetSelected(HamburgerButtonInfo previous, HamburgerButtonInfo value)
{
if (previous != null)
IsOpen = false;
I have just seen that the fix isn't in the directory and in the currently nuget and so the bug is still there.
https://github.com/Windows-XAML/Template10/blob/master/Template10%20%28Library%29/Controls/HamburgerMenu.xaml.cs#L432