In my MAUI application, I like to redirect the user to a different page rather than MainPage in particular condition. For example,
public partial class App : Application
{
public App(UserSettings settings, Database database)
{
InitializeComponent();
long id = settings.DefaultPage;
if (id == 0)
MainPage = new AppShell();
else
MainPage = new MyPage(new MyPageViewModel(database) { Id = id });
}
}
The MyPage has a parameter Id
defined like
[QueryProperty("Id", "Id")]
public partial class MyPage: ContentPage {
public MyPage(MyPageViewModel model)
{
InitializeComponent();
vm = model;
BindingContext = vm;
}
long _id;
public long Id
{
get => _id;
set
{
_id = value;
vm.Init(_id);
}
}
}
Is there a way - correct way - to set up the MainPage without creating a new model by using the dependency inject? How can I set a page with parameters as a MainPage?