Hi,
In my Xamarin.Forms implementation, I have a MasterPage which is in fact a MasterDetailPage. The code for this page is:
public class MasterPage : MasterDetailPage
{
public Dictionary<MenuType, NavigationPage> Pages { get; set; }
MenuView menuView;
public MasterPage()
{
Pages = new Dictionary<MenuType, NavigationPage>();
BindingContext = new MenuViewModel();
Master = menuView = new MenuView();
_homeView = GetPage(menuView.PageSelection) as HomeView;
var homeNav = new NavigationPage(_homeView)
{
BarBackgroundColor = Helpers.Color.KnowNowBlue.ToFormsColor(),
BarTextColor = Color.White
};
Detail = homeNav;
Pages.Add(MenuType.Home, homeNav);
menuView.PageSelectionChanged = PageSelectionChanged;
}
private HomeView _homeView;
private SettingsView _settingsView;
private void PageSelectionChanged(MenuType menuType)
{
NavigationPage newPage;
if (Pages.ContainsKey(menuType))
{
newPage = Pages[menuType];
}
else
{
newPage = new NavigationPage(GetPage(menuType))
{
BarBackgroundColor = Helpers.Color.KnowNowBlue.ToFormsColor(),
BarTextColor = Color.White
};
Pages.Add(menuType, newPage);
}
Detail = newPage;
Detail.Title = GetPage(menuView.PageSelection).Title;
IsPresented = false;
}
private Page GetPage(MenuType type)
{
switch (type)
{
case MenuType.Home:
return _homeView ?? (_homeView = new HomeView());
case MenuType.Settings:
return _settingsView ?? (_settingsView = new SettingsView());
default :
return null;
}
}
It is somewhat similar to this application: https://github.com/jamesmontemagno/Hanselman.Forms/tree/master/Hanselman.Shared.
Anyway, when my HomeView is shown in the Detail page, I can click some items on that View which pushes another page into the detail page. The code for this is:
listView.ItemTapped += (sender, args) =>
{
if (listView.SelectedItem == null)
return;
var content = listView.SelectedItem as Content;
var page = new ArticleView(content)
{
Title = string.Format("{0}", content.Title)
};
Navigation.PushAsync(page);
listView.SelectedItem = null;
};
This pushes the page correctly and on iOS, if I swipe from left to right, the page goes back to the previous. But on Android, the Navigation drawer comes up and I don't want that. If I push the back button or the back button in the topleft corner, the view pops of the stack and I'm back in the previous view.
Why does the Navigation drawer stays active while I pushed a view. And why does this behaviour doesn't occur on iOS.