Skip to content

Instantly share code, notes, and snippets.

@dylanberry
Last active March 5, 2020 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dylanberry/d6c90d6c93a65b389cba61e6d224bdd7 to your computer and use it in GitHub Desktop.
Save dylanberry/d6c90d6c93a65b389cba61e6d224bdd7 to your computer and use it in GitHub Desktop.
public bool PromptToConfirmExit
{
get
{
bool promptToConfirmExit = false;
if (MainPage is ContentPage)
{
promptToConfirmExit = true;
}
else if (MainPage is Xamarin.Forms.MasterDetailPage masterDetailPage
&& masterDetailPage.Detail is NavigationPage detailNavigationPage)
{
promptToConfirmExit = detailNavigationPage.Navigation.NavigationStack.Count <= 1;
}
else if (MainPage is NavigationPage mainPage)
{
if (mainPage.CurrentPage is TabbedPage tabbedPage
&& tabbedPage.CurrentPage is NavigationPage navigationPage)
{
promptToConfirmExit = navigationPage.Navigation.NavigationStack.Count <= 1;
}
else
{
promptToConfirmExit = mainPage.Navigation.NavigationStack.Count <= 1;
}
}
else if (MainPage is TabbedPage tabbedPage
&& tabbedPage.CurrentPage is NavigationPage navigationPage)
{
promptToConfirmExit = navigationPage.Navigation.NavigationStack.Count <= 1;
}
return promptToConfirmExit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment