Falko Falko - 1 month ago 8
Android Question

Xamarin.Forms: Why is MasterDetailPage.IsPresentedChanged raised three times on Android?

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;
}
}


(hosted on GitHub)

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?

Answer

Ok, with the current version 1.4.0 of Xamarin.Forms the issue seems to be fixed. Opening the slide-out menu yields exactly one "True", closing it yields "False" - just as expected.

Comments