C#C
C#4y ago
reeeeeee

MAUI navigation to new page with injected viewModel

If you think this belong more into No Access channel I can move, but I think some of you who are more familiar with dependency injection might be able to understand/help.
In .net MAUI there is a dep.inj and I watched some tutorial where they injected ContentPage classes, as well as viewModels (and those have some injected stuff in constructors as well).
So currently I have something like this:
public App(MainPage mainPage)
{
    MainPage = mainPage);
}

and my Mainpage constructor would be public MainPage(MainViewModel viewModel)
THis is what happens when you open the app. But what about navigating to another page, for example public SecondPage(SecondViewModel viewModel)
Without injected viewModel I could do await App.Current.MainPage.Navigation.PushAsync(new SecondPage()); but now it gives an error becase of missing VM. So how should I approach this? Should I inject SecondViewModel in the mainViewModel as well, and navigate to another page like await App.Current.MainPage.Navigation.PushAsync(new SecondPage(secondViewModel)); or is there any otehr way?
Was this page helpful?