Root ContentPage
This is by far the simplest, and the least flexible. It restricts us to having a single ContentPage
for the entire application.
The objective here is quite simply to get a reference to a suitable ContentPage
and assign it to App.MainPage
in the App constructor, so if you're a bit of a maverick you can just new up your ContentPage
, set its BindingContext
to something, and make the assignment, something like this:
What if your MyRootPage
or (more likely) your MyRootPageVm
has dependencies? Things can start to turn ugly, so let's do this using IoC ...
Once you have added your Page and ViewModel to the IoC container (in MauiProgram.cs), you can do this:
Simple.
Last updated