Replies: 2 comments 4 replies
-
Hello, I was just wondering if you had managed to find a solution for this? I could also do with handing page instantiation this way. Have you tried asking in the MAUI Q&A site? https://docs.microsoft.com/en-us/answers/topics/460228/dotnet-maui.html |
Beta Was this translation helpful? Give feedback.
4 replies
-
Heh, I had the same question in a more roundabout way |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
are Pages that are defined in the visual hierarchy only ever instantiated once? And if that is the case is there a way to clear the cache and force the creation of a new Page instance the next time I navigate to it?
For example the following hierachy is described in a
AppShell.xaml
:The LoginPage constructor gets called when the App is started. Navigate to the AboutPage with
Shell.Current.GoToAsync($"//{nameof(AboutPage)}")
and its constructor gets called.Now lets say the AboutPage has a Logout-Button which does some things and at the end it calls
Shell.Current.GoToAsync($"//{nameof(LoginPage)}")
. The LoginPage constructor does not get called. Navigate back from the LoginPage to the AboutPage and its constructor also does not get called.The same deal if I would navigate from the LoginPage to the SecretPage. The constructor of SecretPage would only get called the first time.
Lets say I use ViewModels for all those Pages. I can't really create a state in the ViewModel constructor because the Page only gets instantiated once and so in my case the ViewModel also only gets instantiated once. I would need to do the work in a OnAppearing.
I would want for the Pages after the LoginPage to always be newly constructed in order to make sure that theres a clean state.
PS:
A lot of examples also contain DetailsPages... something like ItemsDetails, MonkeyDetails, CatDetails etc... Those Pages are never declared in the
AppShell.xaml
but are registered like soand from what Ive seen seem to be always instantiated every single time theyre navigated to.
Beta Was this translation helpful? Give feedback.
All reactions