Organizing a New .NET MAUI Project

New .NET MAUI Project

When you first create a .NET MAUI project using Visual Studio the default layout puts your pages in the top level folder of the project. We are going to create a set of folders to store our files in a way that satisfies the separation of concerns software engineering principle.

Add Folders for Separation of Concerns

Create the following folders in the top level of your project solution

  1. ContentViews
    • Don’t add if you are not going to use ContentViews.
  2. Database
    • This is where your database configuration files will go.
  3. DTO
    • Here is where your data transfer object files will go.
  4. ViewModels
    • Here is where you put your ViewModels for your Content Pages.
  5. Views
    • Here is where you put your ContentPages and their code behinds.

Delete MainPage.xaml from the newly created project.

Right click on your “Views” folder and click “Add->New Class”. Select “.NET MAUI” then “.NEW MAUI ContentPage (XAML)”. Give the page a new and click “Create”.

Now your ContentPage’s XAML markup for the code behind class is designated as being in the “Views folder”:

Make sure to put all future ContentPages for your project in the “Views” folder.

Change your AppShell.xaml file to look for its ContentPages in your newly created “Views” folder.

When your project is first created AppShell.xaml will use the XAML markup “local” to try to find your ContentPages. This XAML markup points at the top level folder of your project.

We created a new folder called “Views” that we want to put all of our ContentPages in, so we have to create new XAML markup to point to this location.

Add the following markup to your AppShell.xaml page:
xmlns:views=”clr-namespace:PROJECTNAME.Views”

Note in the image above, we now use “views” rather than “local” in the ContentTemplate section of our ShellContent. ShellContent points at a specific ContentPage.

Comments

  1. israelnightclub.com Avatar
    israelnightclub.com

    It ís nearly impossible to find educated people in this particular subject, however, you seem like you know what you’re talking about! Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *