Hi everybody.
.net 7, VS 2022 latest, default maui application, mvvm toolkit, an half cup of coffee remaining.
I am porting, as a POC, an Android Application to MAUI.
I can successufully parse the deep link, and extract 'appmode' variable, storing it in a global variable. Url is a kind of myapp://.... &appmode=A&...
In the Android code, if appmode is A or B I inflate the correct Fragment and works flawlessy.
In MAUI I can in the App.cs constructor switch and set MainPage
switch (Globals.AppMode)
{
case AppModeEnum.A:
MainPage = new NavigationPage(new APage());
break;
.... however this happens Before I parse querystring/deeplink in Platform/Android/MainActivity/OnCreate, so Globals.Appmode is not correctly set... yet.
Playing with AppShell (and using a different approach), for unknown reason, I loose the navigation and my pop/push async are ignored. I know I have to write the code, to explain but I will keep this post shorter.
Navigation is done with Mvvm (coomunity toolkit) messaging because of my experience in WPF, so the (root) View (PageA or PageB) registers and captures the message and navigate to correct View, populating the BindingContext received from NavigateToMessage parameter.
In PageA.cs code behind
WeakReferenceMessenger.Default.Register<NavigateToMessage>(this, async (s, e) =>
{
DocumentPage d = new();
d.BindingContext = e.ViewModel;
await Navigation.PushAsync(d);
});
So, sorry for the long description, is there a way to set the start/root page in my app, after deeplink is processed, and preserve the navigation functions?
Just for be complete, if app starts in mode A it has own Pages ad views and never "switch" in mode B, or viceversa. if PageA is root it will be for all app lifecycle.
Many thanks
it seems correct, you should have your data before the root page start, isn't it?
Here it is.
Globals.ParseQueryString is a method for estract the querystring data and store them in global parameters.
Bye.
No Alessandro,
the switch statment is inside the App.cs constructor; it is executed before the code in OnCreate of MainActivity. Breakpoint verified :-)
Sign in to comment