Skip to content
Home » Basics of .NET MAUI – Part 1 – Introduction to .NET MAUI

Basics of .NET MAUI – Part 1 – Introduction to .NET MAUI

Spread the love

Some time ago I wrote a book about GUI programming with Python and Kivy. In the book we were creating a project from scratch. Throughout the book we were talking about all the different topics that I found important to cover so that you are equipped with knowledge that will enable you to write GUI apps with Kivy on your own. Here are some screenshots from the completed project:

Or this one:

The project, called Slugrace, is a game that combines a typical GUI application with animated graphics. This is a game for 1-4 players who put their bets on 4 slugs.

Some time ago I came across the .NET MAUI framework, which uses C# instead of Python. I like it very much and have been learning it for a couple months now. I thought to myself that the best way of learning is by doing, so I decided to rewrite the Slugrace project using the .NET MAUI framework. Besides, this gives me the opportunity to share with you, guys, which is great. But, as I just mentioned, I’m by no means an expert, I’m just learning, like probably many of you. So, if you find any errors, please, let me know. I will be grateful for your feedback. Maybe you’re a more advanced learner than I am. Maybe you notice that something I do, even if it works, could be done in a better way. If so, also let me know.

At the end of the day maybe I’ll use all the posts to write an ebook, who knows.

I also must add that, unlike the Kivy project, which was meant only for the desktop, this time I’m going to target both the desktop and mobile. I’ll be using Windows for the desktop version and Android for the mobile version.

Now, with that said, let’s stop for a minute and think about what actually is .NET MAUI and what you can use it for.

What Is .NET MAUI? 

Let’s start with the name, .NET MAUI. It stands for .NET Multi-platform App UI, so, as you can see, it’s a cross-platform framework for creating native mobile and desktop applications. It’s open-source and relatively new. It’s the evolution of Xamarin.Forms, if you know that framework.

In .NET MAUI we use C# to write the code. Although we can use just C# for most of our project, there’s also the XAML markup language that, although optional, is practically always used because it makes it so much easier to create the presentation part of the app. In our project we’ll be using C# and XAML.

You can use .NET MAUI to create apps for Windows, macOS, Android and iOS from a single shared code base.

How Does .NET MAUI Work? 

The idea behind .NET MAUI is to put as much code as possible in a single code base. But still, you can tweak the code for particular platforms if need arises. The code you write interacts with the .NET MAUI API, which, in turn, directly consumes the native platform APIs: WinUI 3, .NET Android, .NET iOS and .NET macOS. Building apps for macOS and iOS requires a Mac computer, but in this series we’ll be building our app for Windows and Android.

What You Will Need

In order to write your code, you need an editor or IDE. In this series we’ll be using Visual Studio 2022 with the .NET Multi-platform App UI development workload installed, so make sure you have it on your computer and you’ll be good to go.

As we want to build our app also for Android, you will need an Android device or an emulator. We’ll be using an emulator. Installing an emulator is described in the .NET MAUI documentation, so I’m not going to repeat it here. The instructions there are pretty clear. Just make sure to enable hardware acceleration or else your emulator will work very slowly. To create an emulator, in Visual Studio, in the Tools menu go to Android and select Android Device Manager:

In the manager you’ll see the list of all installed devices:

There’s just one on my machine right now. Your list will most probably be empty when you open this window for the first time. Just click the +New button and select the device you want to use to emulate a real Android device. The installation may take some time. You can pick a model and set some properties of the device.

Hit the Create button when you’re done with that. Again, consult the documentation for more details. Anyway, I assume you have Visual Studio 2022 installed (the free Community version is just fine) and also an Android emulator. If so, we’re ready to start a new project. This is what we are going to do in the next post.


Spread the love
Tags:

Leave a Reply