Xamarin - Hamburger Some Menu by clicking Back WP button

Asked

Viewed 259 times

1

I am using the code below to create a Master Detail menu in Xamarin. The code works perfectly on Android but on Windows Phone it has a bug that I am unable to solve.

Mainpage.Cs

using AppNewsPlay.MenuItems;
using AppNewsPlay.Views;
using System;
using System.Collections.Generic;
using Xamarin.Forms;

namespace AppNewsPlay
{
    public partial class MainPage : MasterDetailPage
    {
        public List<MasterPageItem> menuList { get; set; }

        public MainPage()
        {
            InitializeComponent();

            menuList = new List<MasterPageItem>();


            // setando os icones e passando parametros para as paginas
            var page1 = new MasterPageItem() { Title = "Home", Icon = "ic_home_black_24dp.png", TargetType = typeof(Home) };
            var page2 = new MasterPageItem() { Title = "Xbox", Icon = "ic_dashboard_black_24dp.png", TargetType = typeof(Xbox) };
            var page3 = new MasterPageItem() { Title = "Playstation", Icon = "ic_games_black_24dp.png", TargetType = typeof(Playstation) };
            var page4 = new MasterPageItem() { Title = "Jogos", Icon = "ic_videogame_asset_black_24dp.png", TargetType = typeof(Jogos) };
            var page5 = new MasterPageItem() { Title = "Nintendo", Icon = "ic_phonelink_black_24dp.png", TargetType = typeof(Nintendo) };
            var page6 = new MasterPageItem() { Title = "Artigos", Icon = "ic_description_black_24dp.png", TargetType = typeof(Artigos) };
            var page7 = new MasterPageItem() { Title = "Sobre", Icon = "ic_info_black_24dp.png", TargetType = typeof(Sobre) };
            var page8 = new MasterPageItem() { Title = "Contato", Icon = "ic_perm_contact_calendar_black_24dp.png", TargetType = typeof(Contato) };

            //Adicionando Itens ao menu
            menuList.Add(page1);
            menuList.Add(page2);
            menuList.Add(page3);
            menuList.Add(page4);
            menuList.Add(page5);
            menuList.Add(page6);
            menuList.Add(page7);
            menuList.Add(page8);



            //Adicionando os itens ao ListView na MainPage.xaml
            navigationDrawerList.ItemsSource = menuList;

            // Criando a Instancia da Pagina Inicial na Pagina Home
            Detail = new NavigationPage((Page)Activator.CreateInstance(typeof(Home))) { BarBackgroundColor = Color.FromHex("#000000"), BarTextColor = Color.White };


            // criando o bind para repassar a lista
            this.BindingContext = new
            {

                Header = "",
                Image = "novo_logo_40dpi_newsplay.png",
                // Rodape 
                Footer = ""


            };

            // desabilitando o indicador de carregamento
            waitActivityIndicator.IsRunning = false;
            // ocultando a barra
            waitActivityIndicator.IsVisible = false;

        }
        // função para o click do botão na lista
        private void OnMenuItemSelected(object sender, SelectedItemChangedEventArgs e)
        {

            var item = (MasterPageItem)e.SelectedItem;
            Type page = item.TargetType;
            Detail = new NavigationPage((Page)Activator.CreateInstance(page)) { BarBackgroundColor = Color.FromHex("#000000"), BarTextColor = Color.White };
            IsPresented = false;

        }

        protected override bool OnBackButtonPressed()
        {
            base.OnBackButtonPressed();

            return true;

        }



    }
}

When I click on a news and then click on back button Windows Phone simply stops displaying the Hamburger menu, displaying only the screen contents without the menu, how-to suggestions?

see images

inserir a descrição da imagem aqui inserir a descrição da imagem aqui

To call the next screen I use the following code.

   // Função que retorna o item selecionado da aba Ultimas Noticias
        private async void OnItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
                    if(e.SelectedItem !=null)
                    {
                        var selection = e.SelectedItem as UltimasNoticias;
                        var PostView = new PostView(selection.Id);
                        await Navigation.PushAsync(PostView, true);
                        #region DisabledSelectionHighlighting
                        ((ListView)sender).SelectedItem = null;
                        #endregion

                    }

        }
  • tries to remove base.Onbackbuttonpressed(); from the override you made.

  • tries to set the isVisible = true of the menu when you click the back button

1 answer

1

I had this problem a little while ago. I solved it in an easy way in my project. Go to your MainPage.xaml and add to the tag MasterDetailPage:

NavigationPage.HasNavigationBar="False"

What happens is that your project is with 2 statusbar, one must be hidden.

  • thanks for the tip! until today I have not solved this kkkk

  • even with that did not solve ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.