First Look at .NET MAUI
Image by Stephen Hustedde with background photo by Pascal Debrunner

First Look at .NET MAUI

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:

No alt text provided for this image
Sample XAML Code from the Codeword Challenge .NET MAUI game

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”:

No alt text provided for this image
Sample XAML Code from the Codeword Challenge .NET MAUI game showing the Clicked reference

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:

No alt text provided for this image
The functuionality of the "Let's Play" button's Clicked event is written in the C# code file that backs the XAML page.

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.

  • Variables
  • Comments
  • "Input > Process > Output" model
  • Conditionals
  • Repetitions (loops)?– both “for” and “while
  • Nested structures?(condition structures nested inside loops, conditions nested in conditions)
  • Ternary conditional statements?(not needed, but my choice for readability)
  • Random number generator
  • Concatenation of strings
  • Mathematic expressions?(minimal, but I keep some game statistics)
  • Data formatting?(changing numeric data to string and formatting numbers as a percent)
  • Lists?and arrays (Data structures)
  • Functions/methods?

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:

要查看或添加评论,请登录

Stephen Hustedde的更多文章

  • Characteristics of Good/Great Programmers

    Characteristics of Good/Great Programmers

    With almost thirty-five years of teaching computer programming and software development at South Mountain Community…

    3 条评论
  • Why Learn Programming?

    Why Learn Programming?

    There’s been a movement in recent years that everyone should learn how to code. The code.

  • The Value of Mastering Excel

    The Value of Mastering Excel

    And using Excel to write programming code. by Stephen Hustedde If you’ve taken a basic computing literacy class, you’ve…

  • What is .NET?

    What is .NET?

    What is .NET? By Stephen Hustedde (South Mountain Community College faculty) – October 2022 ? 2022, Stephen Hustedde…

  • Debugging Tips in Python

    Debugging Tips in Python

    Even the best and most experienced programmers have to test and debug their code. And the more complex the project, the…

    2 条评论

社区洞察

其他会员也浏览了