First Look at .NET MAUI
Stephen Hustedde
Faculty- CIS (Software Development); past Interim Dean of Academic Innovation; and past mCLCTL Division Chair (myCareer, Library and Center for Teaching and Learning) at South Mountain Community College
Microsoft recently released the?.NET MAUI?framework as an extended upgrade to their?Xamarin?framework for cross-platform development coded in C#. I've been teaching Xamarin (CIS165DC) as part of our C# cohort for many years at South Mountain Community College in Phoenix, and have been eagerly awaiting the update to MAUI, with plans to revamp our CIS165DC offering for next fall to focus on .NET MAUI. ?
Like Xamarin Forms, .NET MAUI projects provide cross-platform capabilities with shared code. Traditionally, we would write Android apps in the Android Studio IDE (Integrated Development Environment) using the Kotlin programming language (or previously Java). Apps for the iPhone or iPad (iOS), as well as the Macintosh desktop, are written in the Swift programming language within the Xcode IDE. We create applications for the Windows ecosystem, writing our code in C# using the Microsoft Visual Studio IDE. Three IDE development tools. Three programming languages. Ouch. However, in .NET MAUI, we can use one tool (Visual Studio) and one language (C#) to create natively-ran cross-platform projects for Android, iOS, MacOS, Windows and even Tizen (most notably Samsung TVs).
I carved out a day last summer to finally explore a preview version of .NET MAUI. I often create games and apps for fun and to keep my skills up, and I’ve had a desire to create a Wordle-type app for Android and iOS phones for few months now. Naturally, that became my first MAUI-based app. Bottom line, developing in .NET MAUI is not much different from creating a Xamarin app project.
The graphical user interface (GUI) is created with either XAML (Extensible Application markup Language) and/or in the underlying C# code. I prefer to use XAML, which is similar to writing HTML code for a web page. For this project I used both XAML and C# in displaying the interface. In the XAML code, prescribed layouts contain views (controls) to present interactive buttons, labels, text entry fields, images and scrollable lists. The functionality of the buttons and other views is written in a linked C# file. One of the great things about .NET MAUI (and Xamarin before it) is each platform is compiled using the native APIs of that platform. This means that a button looks and behaves like an iOS button on an iPhone, but looks and behaves like an Android button on my Samsung Galaxy.
Here some sample XAML code:
领英推荐
For a button, the XAML Code provides a “Clicked” event reference. The “Let’s Play” button on the main page references the event of “OnPlayClicked”:
Each XAML page has an associated C# file that contains the functional code. The C# file is referred to as the “code behind”.?Here is a sample of the C# code for the:
The C# code uses all the skills, concepts and techniques I would use in writing a Windows application, and what I cover in the beginning programming classes I teach, regardless whether they be conducted in C#, Python, Swift, Kotlin or VisualBasic.
So how much code did I write??About 300 lines of underlying C# code to make everything function smoothly. That excludes comments, blank lines and bracketed { } structure lines. And about another 200 lines of XAML code (similar to HTML) to create the GUI interface for all three XAML pages (MainPage, GamePlay, and Instructions).?The project took me a full day of design, coding, testing/debugging. Quite a bit of testing and debugging! Satisfied with the first phase, I deployed it by sideloading to my Android (Samsung Galaxy) phone just for me to enjoy. But I also wanted to document the experience of submitting it to the Play store. I started with Android. Perhaps I’ll port it over soon to the Apple side.
Deployment: There are numerous hoops to jump through to get an app accepted to the platform stores! I had to create and add icons, provide additional code to modify the layout for a tablet device with larger resolution, and create the Release installer (APK file for Android). To put an app in the Google Play store, one has to create a webpage for support and provide a privacy policy. I also had to generate screen shots on various devices, create a large billboard advertisement for use in the Store, and (optionally) make a video trailer (seen above). It takes about two weeks for the Google vetting team to review and test . . . and (fingers-crossed) approve. I’m excited to say Codeword Challenge is now available for Android phones and tablets in the Google Play store! Here's the link: