When I started working with Xamarin.Forms, I found that MasterDetailPage did not do what I wanted and contained multiple bugs. I therefore wrote something to replace MasterDetailPage in my own code, to get the precise result I wanted.
I thought I'd take a peek at the current state of MasterDetailPage (using XF 2.4.0.38779) to see how it has changed since then.
At https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/navigation/master-detail-page/
it says:
"The MasterDetailPage.Master property is set to a ContentPage instance. The MasterDetailPage.Detail property is set to a NavigationPage containing a ContentPage instance."
and:
"The MasterDetailPage.Master page must have its Title property set, or an exception will occur."
Following those two guides, and using MasterBehavior.Split, I find that the Title set on the Master page is not displayed. It seems odd that setting it is required if it's not then displayed. Am I missing something?
Also, on that same page, it says:
"MasterDetailPage is designed to be a root page, and using it as a child page in other page types could result in unexpected and inconsistent behavior. In addition, it's recommended that the master page of a MasterDetailPage should always be a ContentPage instance, and that the detail page should only be populated with TabbedPage, NavigationPage, and ContentPage instances. This will help to ensure a consistent user experience across all platforms."
I find that if I use MasterDetailPage as a child page, on UWP the Detail page's Title is displayed twice. Must be one of those "unexpected and inconsistent behaviors". Seems odd though - if it was going to do something like that, I would have expected that to happen on Android and UWP as well. Makes me wonder if UWP is not kept quite up to date with Android and UWP when it comes to MasterDetailPage...
The good thing is that this latest dabble with MasterDetailPage makes me think creating my own replacement was the right thing to do, even if it took a fair amount of work.
For info, the hacky code I used whilst dabbling with this today is as follows:
using Xamarin.Forms;
namespace ViewsUsingXamarinForms
{
public class MyAppMasterDetailPage : MasterDetailPage
{
public MyAppMasterDetailPage()
{
Master = new ContentPage
{
BackgroundColor = Color.Yellow,
Content = new StackLayout
{
VerticalOptions = LayoutOptions.Center,
Children =
{
new Label
{
HorizontalTextAlignment = TextAlignment.Center,
FontSize = 30,
BackgroundColor = Color.Blue,
TextColor = Color.Aqua,
Text = "Master"
}
}
},
Title = "Master ContentPage title"
};
Detail = new NavigationPage(new ContentPage
{
BackgroundColor = Color.Yellow,
Content = new StackLayout
{
VerticalOptions = LayoutOptions.Center,
Children =
{
new Label
{
HorizontalTextAlignment = TextAlignment.Center,
FontSize = 30,
BackgroundColor = Color.Green,
TextColor = Color.Lime,
Text = "Detail"
}
}
},
Title = "Detail ContentPage title"
})
{
Title = "Detail NavigationPage title"
};
Title = "MasterDetailPage title";
MasterBehavior = MasterBehavior.Split;
}
} // public class MyAppMasterDetailPage : MasterDetailPage
} // namespace ViewsUsingXamarinForms
// eof