Learning .NET Maui Part 1

As noted in part 0, I assume you are a Xamarin.Forms/C# programmer, familiar with Visual Studio. This series is not about converting your existing Xamarin.Forms apps; rather it is about converting your brain to MAUI. Since I’m learning as I’m going, your mileage may vary.

To get started, install the preview edition of Visual Studio 2022 (that may not be necessary by the time you’re reading this) which fully supports MAUI. Next, create a new project. We’ll call it ZipCodeFinder because we’ll be using the web service ZipWise which is free for limited use (which is all we’ll need).

Open VS, create a new project, and choose the .NET MAUI app template:

All In One Project

Notice that the entire solution is now in one project. You could make the argument either way for this design, but this is what Microsoft decided, so let’s go with that.

Start it up on your platform of choice, just to see it running, and then take a quick walk through the folders and files you get out of the box. Go ahead, I’ll wait here.

Take a look at the Resources folder in a bit more depth. The thing to suss out here is that the resources are not divided by platform. You put all your resources in one place, and .NET MAUI (from now on I’m just writing MAUI – so sue me) takes care of them. This is mind-blowing. You give it an image and it does all the scaling and management for all the different platforms! Same with fonts, etc. Boy! Would that have made Xamarin.Forms life easier.

Now look in the Platforms folder. What’s going on in there is what allows your MAUI app to run on all those platforms, and is also where you can write platform-specific code without conditional compilation.

While you are in this mindset, it can be valuable to look at the project’s properties. If you go through the context menu, you get to a nice wizard for that.

Start Up File

Next, open up MauiProgram.cs. This is the startup file. Sparse for now, but we’ll be registering our services here and doing other fun stuff, so stay tuned. Keep an eye on that builder object — it will be the heart of our Dependency Injection.

The Shell

Here is one place that we depart from what most of us are used to. The shell can hold flyouts, tabs, etc. but is really the way to structure and navigate within your app. The Shell has content pages which is laid out much like pages in Xamarin.Forms (e.g, only one item but it can be a layout item).

We’ll be looking at the shell in depth in coming blog posts.

More to come, soon…

About Jesse Liberty

Jesse Liberty has three decades of experience writing and delivering software projects and is the author of 2 dozen books and a couple dozen online courses. His latest book, Building APIs with .NET will be released early in 2025. Liberty is a Senior SW Engineer for CNH and he was a Senior Technical Evangelist for Microsoft, a Distinguished Software Engineer for AT&T, a VP for Information Services for Citibank and a Software Architect for PBS. He is a Microsoft MVP.
This entry was posted in Essentials and tagged , . Bookmark the permalink.