I have the following minimal example of an app using Xamarin.Forms (version 1.2.3) and a MasterDetailPage
(similar to: "Show "Back to Menu" Button in iOS NavigationBar with Xamarin.Forms"):
public static class App
{
static MasterDetailPage MDPage;
public static Page GetMainPage()
{
MDPage = new MasterDetailPage {
Master = new ContentPage {
Title = "Master",
Icon = Device.OS == TargetPlatform.iOS ? "menu.png" : null,
Content = new Button {
Text = "Open detail",
Command = new Command(o => {
MDPage.Detail = new NavigationPage(new ContentPage());
MDPage.IsPresented = false;
}),
},
},
Detail = new NavigationPage(new ContentPage()),
};
MDPage.IsPresentedChanged += (sender, e) => Console.WriteLine(DateTime.Now + ": " + MDPage.IsPresented);
return MDPage;
}
}
When opening or closing the MasterPage
via button click on Android, the IsPresentedChanged
event is triggered three times instead of once. According to the command line output the IsPresented
property is either toggling as True
-False
-True
or False
-True
-False
, respectively.
Opening or closing using a swipe gesture or tapping on the DetailPage
does work well. On iOS there is no problem at all.
Is there something I'm doing wrong? Or is there a simple workaround to get a reliable event?