How to check if Page is MainPage?

Jassim Al Rahma 1,526 Reputation points


I have a ContentPage which i show as PushModalAsync but in one case I am showing it as MainPage

How can I check how the page was opened? was it opened as PushModalAsync or MainPage?


A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,298 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,350 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 69,306 Reputation points Microsoft Vendor


    Welcome to our Microsoft Q&A platform!

    If you open page as PushModalAsync. You can use var CurrentPage = Navigation.ModalStack.ToList<Page>().Last<Page>(); code to get the current display page.

    If you want to get all of opened page by PushModalAsync. Please use following code.

       List<Page> pages= Navigation.ModalStack.ToList<Page>();  

    Best Regards,

    Leon Lu

    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

0 additional answers

Sort by: Most helpful