How do I determine and display the correct content page in .NET MAUI app at start up?

118 views Asked by At

I'm new to .NET Maui and what I'm looking to do is at startup, check if there is any database files available. If there are, I want to display a popup page that has a list of those databases where the user can select a specific one to use in the app.

If no databases were found I want to display a page that will allow the user to create a new database.

I have a very basic understanding about MVVM and binding, but I noticed in the App.xaml and AppShell.xaml files seems to be where the content pages are executed.

So where do I go from here?

I noticed there is an OnStart method I can use in the App.xaml.cs file by doing something like:

protected override void OnStart()
{
  base.OnStart();
  // add code here.
}
1

There are 1 answers

0
Jason On

You could do something like this

protected override void OnStart()
{
  base.OnStart();
  
  if (CheckDBExists()) 
  {
      MainPage = new SelectDBPage();
  }
  else
  {
      MainPage = new CreateDBPage();
  }
}