How to check if Page is MainPage?

Jassim Al Rahma 1,591 Reputation points
2021-08-25T19:41:18.933+00:00

Hi,

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?

Thanks,
Jassim

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,366 questions
C#
C#
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.
11,128 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 77,406 Reputation points Microsoft Vendor
    2021-08-26T03:12:40.043+00:00

    Hello,​

    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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.