question

JassimAlRahma-9056 avatar image
0 Votes"
JassimAlRahma-9056 asked LeonLu-MSFT commented

How to check if Page is MainPage?

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

dotnet-csharpdotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

LeonLu-MSFT avatar image
0 Votes"
LeonLu-MSFT answered LeonLu-MSFT commented

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.


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,

I tried this in my PushModalAsync opened page:

 var CurrentPage = Navigation.ModalStack.ToList<Page>().Last<Page>();
 App.Current.MainPage.DisplayAlert("CurrentPage", CurrentPage.ToString(), "");


but getting:

System.ArgumentNullException: Value cannot be null.
Parameter name: cancel


0 Votes 0 ·

Please add a string to third parameter like following code. Do not leave it to empty.

App.Current.MainPage.DisplayAlert("CurrentPage", CurrentPage.ToString(), "Ok");


126898-image.png


1 Vote 1 ·
image.png (85.7 KiB)