Back Button does not appear in NavigationBar XamarinForms

1

I have a Menu Burger with a ListView where in the Click of the line of the listview I call this method to open a Modal, however the NavigationBar does not appear the BackButton.

    public async Task OpenModalAsync(Page poPage, bool bNavigationPage = true)
    {

        if (bNavigationPage)
            await Application.Current.MainPage.Navigation.PushModalAsync(new NavigationPage(poPage), true);
        else
            await Application.Current.MainPage.Navigation.PushModalAsync(poPage, true);
    }

I have tried to use the method, but with no result

    NavigationPage.SetHasBackButton(this, true);

I noticed that in the PushAsync method it places the BackButton.

    
asked by anonymous 20.03.2018 / 20:06

1 answer

1

If on your harmburger menu you are in the "Root" screen it will not even appear.

I used in my project according to the item selected as PushModalAsync, in this case it does not have the back button but can use as PushAsync

You can create this way:

public interface INavigationService
    {
        Task PopModalAsync();
        Task NavigateToSubCategoria(Categoria categoria);
    }

public class NavigationService : INavigationService
    {
        public async Task PopModalAsync()
        {
            await NavigationHelper.PopModalAsync();
        }

        public async Task NavigateToSubCategoria(Categoria categoria)
        {
            await NavigationHelper.PushModalAsync(new SubCategoriasPage(categoria));
        }
    }

CodeBehind:

private readonly INavigationService _navigationService;
        public CategoriasPage ()
        {
            InitializeComponent ();
            _navigationService = DependencyService.Get<INavigationService>();
        }

    void OnItemTapped(Object sender, ItemTappedEventArgs e)
            {
                var dataItem = (Categoria)(e.Item);

                _navigationService.NavigateToSubCategoria(dataItem);
            }

Xaml:

<ListView x:Name="ListaCategorias"
          ItemTapped="OnItemTapped">

    </ListView>
    
22.03.2018 / 18:12