Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAUI Navigation #897

Open
ClaytonIndustries opened this issue Mar 5, 2024 · 0 comments
Open

MAUI Navigation #897

ClaytonIndustries opened this issue Mar 5, 2024 · 0 comments

Comments

@ClaytonIndustries
Copy link

ClaytonIndustries commented Mar 5, 2024

Hi I'm having trouble working out how to use the INavigationService in MAUI. In Xamarin Forms we used to override PrepareViewFirst to inject the NavigationPageAdapter object into the container. In MAUI though PrepareViewFirst is never called when using DisplayRootViewForAsync.

Here's what I've got

public App()
{
    InitializeComponent();

    Initialize();

    _container = container;

    _container.PerRequest<HomeViewModel>();
    _container.PerRequest<AnotherViewModel>();

    DisplayRootViewForAsync<HomeViewModel>();
}

// This is never called so no NavigationService will get added to the container
protected override void PrepareViewFirst(NavigationPage navigationPage)
{
    _container.Instance<INavigationService>(new NavigationPageAdapter(navigationPage));
}

From looking at the source code I tried calling PrepareViewFirst() before DisplayRootViewForAsync and that successfully added a NavigationPageAdapter to the container however when INavigationService is injected into a viewmodel calling NavigateToViewModelAsync does nothing.

So how do we navigate between viewmodels in MAUI?

I'm using the latest beta version from MyGet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant