Closing the ContentPage

Jassim Al Rahma 1,566 Reputation points
2022-08-23T21:12:35.533+00:00

Hi,

Ia m using Shell Navigation. and I have a HomePage, from the HomePage I am opening NewPatient ContentPage and once the user entered the new patient then I am opening PatientDetails ContentPage.

When the NewPatient page opens the ContentPage, how can I close the NewPatient?

Thanks,
Jassim

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,412 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 74,491 Reputation points Microsoft Vendor
    2022-08-24T09:19:48.587+00:00

    Hello,

    When the NewPatient page opens the ContentPage, how can I close the NewPatient?

    Do you want to remove the NewPatient page in the navigation task? If so, you can useShell.Current.Navigation.RemovePage(yourNewPatient);` to move it,

    Here is a demo code, If I want to remove NewPatient page in the PatientDetails.

       var myExistingPageList = Shell.Current.Navigation.NavigationStack.ToList();  
               foreach (var item in myExistingPageList)  
               {  
                   if (item != null)  
                   {  
                       if (item.GetType().Equals(typeof(NewPatient)))  
         
                       {  
                           Shell.Current.Navigation.RemovePage(item);  
                       }  
                   }  
               }  
    

    Please note: I use VS community 17.4.0, it is not working. If I execute it in 17.3.0, it is working.

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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.


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.