Skip to content

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

@HimanshuBansal112

Description

@HimanshuBansal112

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions