How to use PushAsync and FlyoutMenu without replacing the FlyoutMenu with the back button

Patricia María Sánchez Maradiaga 20 Reputation points
2023-08-28T16:16:44.94+00:00

I'm using MVVM, so I have an AppConstant where I call the FlyoutMenu depending on the user, but if I use PushAsync to make the navigation in android it doesn't work and I need to put an argument in the navigation and if I disable the button, it doesn't appear either the flyout. How could I make the FlyoutMenu appear and not the Back Button?

Example of my class AppConstant:

PushAsync Button

public async static Task AddFlyoutMenusDetails()
{

	AppShell.Current.FlyoutHeader = new FlyoutHeaderControl();
	var usuario = App.UserDetails;

	var encuestasPagina = AppShell.Current.Items.Where(f => f.Route == nameof(EncuestasPaginaPrincipal)).FirstOrDefault();
	if (encuestasPagina != null) AppShell.Current.Items.Remove(encuestasPagina);


	if (App.UserDetails.RolID == (int)RoleDetails.Entrevistador)
	{
		var user = new UsuarioInfo();
		var flyoutItem = new FlyoutItem()
		{
			Title = "Entrevistador",
			Route = nameof(EncuestasPaginaPrincipal),
			FlyoutDisplayOptions = FlyoutDisplayOptions.AsMultipleItems,
			Items =
			{
						new ShellContent
						{
							Icon = Iconos.Inicio,
							Title = "Inicio",
							ContentTemplate = new DataTemplate(typeof(EncuestasPaginaPrincipal)),
						}
		   }
		};

		if (!AppShell.Current.Items.Contains(flyoutItem))
		{
			AppShell.Current.Items.Add(flyoutItem);
			if (DeviceInfo.Platform == DevicePlatform.WinUI)
			{
				AppShell.Current.Dispatcher.Dispatch(async () =>
				{
				await Shell.Current.Navigation.PushAsync(new EncuestasPaginaPrincipal(usuario));
				});
			}
			else
			{
				await Shell.Current.GoToAsync($"//encuestas?usuario={usuario}");
			}
		}

	}
}
Developer technologies | .NET | .NET MAUI
Developer technologies | Visual Studio | Other
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2023-08-29T02:57:47.4933333+00:00

    Hello,

    Thanks for your feedback.

    After investigation, the appearance of this condition follows the design.

    In the MAUI shell's navigation structure, when you navigate with FlyoutItem, the program actually replaces the first page. But when you use PushAsync or GoToAsync, the program adds this page to the navigation stack.

    When a new object exists in the navigation stack, the back button must appear.

    Therefore, for this issue, it is more recommended that you publish this issue to the GitHub repository to make our developers aware of this need.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.