Menu disappears while navigating from one content page to another

Menu disappears while navigating from one content page to another



I am building a Xamarin App, with a Master Detail Page Layout and When I navigate to a content page from another content aPage. The menu disappears on the content page.



I have three pages: MasterDetailPage.xaml.cs, ListItemsPage.xaml.cs and DepositsPage.xaml.cs



MasterDetailPage.xaml.cs


// Constructor.
public MainPage()

InitializeComponent();
Detail = new NavigationPage(new Login());
IsPresented = false;



//Navigates to the content Page called ListItemsPage.xaml.cs


OnMenuItemSelected()

Detail = new NavigationPage((Page)Activator.CreateInstance(typeof(ListItemsPage));



On Click of a List Item on the ListItemsPage → It should navigate to another content page (Deposits.xaml) and the following is the code I use:


Application.Current.MainPage = new NavigationPage(new DepositsPage());



It navigates to the page but the menu is missing.



I would really appreciate it, if somebody could help me with this as I have been struggling with this the last couple days.




1 Answer
1



When using MasterDetailPage navigation whenever you want to navigate but keeping the menu on the side you have to navigate changing the Detail part as you did when you replaced your Login with ListItemPagebut instead you are changing the whole Application page when you did Application.Current.MainPage


Detail


Login


ListItemPage


Application.Current.MainPage



Something else I see in your code above is that you are not specifying the Master which is the part that should hold your Menu items.


Master



Based on the Xamarin Documentation here you should define your MasterDetailsPage in this way:


public MainPage()

var menuPage = new MenuPage();
Master = menuPage;
Detail = new NavigationPage((Page)Activator.CreateInstance(typeof(ListItemsPage));

menuPage.ListView.ItemSelected += OnMenuItemSelected


OnMenuItemSelected(object sender, SelectedItemChangedEventArgs e)

var item = e.SelectedItem as MasterPageItem;
if (item != null)
Detail = new NavigationPage ((Page)Activator.CreateInstance (item.TargetType));
masterPage.listView.SelectedItem = null;
IsPresented = false;




But the above expects that your MenuPage will have a ListView where each item is a menu option containing all the information required to display the menu option and navigate.


public class MenuPage : ContentPage

public ListView ListView get return listView;

public MenuPage()


Icon = "hamburger.png";
Title = "My great application";

var masterPageItems = new List<MasterPageItem> ();
masterPageItems.Add (new MasterPageItem
Title = "List Items",
IconSource = "list_items.png",
TargetType = typeof(ContactsPageCS)
);
masterPageItems.Add (new MasterPageItem
Title = "Deposit",
IconSource = "deposit.png",
TargetType = typeof(TodoListPageCS)
);

..........




If you follow the documentation for this you should be good. If still with doubts come back here.



Hope this helps.-



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế