Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin forms MasterDetailPage Menu icon not shown on iOS

I have Xamarin.Forms project. I have MasterDetailPage inside NavigationPage. I set icon property of the MasterDetailPage so that icon is supposed to be set as the top left position on the navigation bar. But it does not work.

public partial class App : Application
{
    public App()
    {
        InitializeComponent();

        var masterDetailpage = new MasterDetailPage {
            Icon = "menuIcon.png",
            Master = new Page { Title = "Sample"},
            Detail = new Page()
        };

        MainPage = new NavigationPage(masterDetailpage);
    }
}

This never works. If I put NavigationPage as MasterDetailPage's Detail property, and set icon on the Master. It works. But it is very important to have MasterDetailPage inside NavigationPage and not vise versa.

like image 237
mister_giga Avatar asked Apr 10 '17 15:04

mister_giga


2 Answers

The solution is to set the Icon property of the Page being used for the Master.

 var masterDetailpage = new MasterDetailPage {            
        Master = new Page { Title = "Sample", Icon = "menuIcon.png"},
        Detail = new NavigationPage(new Page())
    };

This assumes you have a png in your iOS project under the Resources folder named menuIcon.png that is the hamburger icon you want. You will also need to use a NavigationPage around the Detail because the Icon is shown in the Navigation Bar area.

like image 136
therealjohn Avatar answered Nov 15 '22 08:11

therealjohn


The Unicode char can be used to show the "hamburger" menu icon.

You may specify Title="☰" for the master page ContentPage-top level tag.

If you use an icon, you may draw a better icon than char. But using Unicode char is simple enough if this is acceptable for you.

It works for iOS and doesn't break Android.

Links:

  • Trigram for heaven (U+2630)
  • The Unicode character for menu icons ("navicons") ☰.
like image 29
sergtk Avatar answered Nov 15 '22 07:11

sergtk