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.

Page changing using menu bar stops command in menu bar from working

See original GitHub issue

Description

Since MenuBarItem did not had command binding option, I chose MenuFlyoutItem. But when doing navigation in it, it stops command in menu bar from working. It doesn’t crash but it stops working.

Steps to Reproduce

Add to MainPage.xaml:

<ContentPage.MenuBarItems>
      <MenuBarItem Text="Pages">
            <MenuFlyoutItem Text="Page1"
                            Command="{Binding TapCommand}"/>
        </MenuBarItem>
</ContentPage.MenuBarItems>

Add to MainViewModel.cs:

		[RelayCommand]
		async Task Tap()
		{
			await Shell.Current.GoToAsync(nameof(Page1));
		}

Add to Page1.xaml

<ContentPage.MenuBarItems>
        <MenuBarItem Text="Options">
            <MenuFlyoutItem Text="GoBack"
                            Command="{Binding GoBackCommand}"/>
            <MenuFlyoutItem Text="Exit"
                            Command="{Binding ExitCommand}"/>
        </MenuBarItem>
    </ContentPage.MenuBarItems>

Add to Page1ViewModel.cs

		[RelayCommand]
		public static void Exit()
		{
			System.Environment.Exit(0);
		}

		[RelayCommand]
		async Task GoBack()
		{
			await Shell.Current.GoToAsync("..");
		}

As usual add to AppShell.xaml.cs

Routing.RegisterRoute(nameof(Page1), typeof(Page1));

and add to MauiProgram.cs

                builder.Services.AddSingleton<MainPage>();
		builder.Services.AddSingleton<MainViewModel>();

		builder.Services.AddTransient<Page1>();
		builder.Services.AddTransient<Page1>();

Link to public reproduction project repository

https://github.com/HimanshuBansal112/NetMauiIssue

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

I was not able test on other platforms

Affected platform versions

Windows 11(Build 22621.1344)

Did you find any workaround?

No

Relevant log output

N/A

Issue Analytics

  • State:open
  • Created 6 months ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
vrishecommented, Mar 29, 2023

Seems like the flyout items’ binding context is getting lost during the navigation process. For me I have ‘fixed’ the issue like this:

protected override void OnAppearing()
{
    base.OnAppearing();

    foreach (var item in MenuBarItems)
    {
        item.BindingContext = BindingContext;
    }
}
0reactions
ooikengsiangcommented, Aug 20, 2023

I have the same issue and @vrishe’s solution fixes it. If we’re not supposed to do things like this (since this is “under consideration”?) how are we supposed to do it??

What vrishe proposed is a workaround, not a fix. Fix mean it should have work correctly as intended, no work around needed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to change page through my menu bar methods in ...
every tutorial I find is through the buttons, and only the buttons.. I am using python 3.6, with tkinter . import tkinter as...
Read more >
How to troubleshoot a frozen menu bar
Doing this should spur the menu bar to change, causing the system to re-draw it and perhaps making it full and functional again....
Read more >
Why Did My Mac Menu Bar Disappear? - YouTube
https://macmost.com/e-2769 If you notice that the Menu Bar at the top of your screen is missing, it is probably because you are using...
Read more >
Change Desktop & Dock settings on Mac
On your Mac, use Desktop & Dock settings to change the appearance of the Dock, and to select items to show in the...
Read more >
How to customize the Menu Bar on Mac
Want to edit Mac menu bar? See the best tips to rearrange, remove, and stack icons in your menu bar to keep all...
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