I'm 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 can not resolve.
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 item and then click the back button , Windows Phone simply stops displaying the Hamburger menu, displaying only the contents of the screen without the menu, suggestions on how to solve it?
view images
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
}
}