I\'m trying to build a cross-platform app using C# and Xamarin.Forms. It contains a slide-out menu implemented in form of a MasterDetailPage. While on Android t
I finally found a solution. The code basically needs two minor corrections:
DetailPages in a NavigationPage, but not the MasterDetailPage (see #1, #2 and #3 below).Icon to the MasterPage when on iOS (see #4 below). Don't forget to a the actual PNG(!) to the iOS resources.The minimum working example is as follows:
public static class App
{
static MasterDetailPage MDPage;
public static Page GetMainPage()
{
return MDPage = new MasterDetailPage { // #1
Master = new ContentPage {
Title = "Master",
Icon = Device.OS == TargetPlatform.iOS ? "menu.png" : null, // #4
Content = new StackLayout {
Children = { Link("A"), Link("B"), Link("C") }
},
},
Detail = new NavigationPage(new ContentPage { Content = new Label { Text = "A" } }), // #2
};
}
static Button Link(string name)
{
var button = new Button { Text = name };
button.Clicked += delegate {
MDPage.Detail = new NavigationPage(new ContentPage { Content = new Label { Text = name } }); // #3
MDPage.IsPresented = false;
};
return button;
}
}