Reader small image

You're reading from  .NET MAUI Cross-Platform Application Development - Second Edition

Product typeBook
Published inMar 2024
Reading LevelBeginner
PublisherPackt
ISBN-139781835080597
Edition2nd Edition
Languages
Right arrow
Author (1)
Roger Ye
Roger Ye
author image
Roger Ye

Roger Ye is an embedded system programmer who has great interest in virtualization, Android, and cross-platform technologies. His professional experience includes working with major companies like Motorola, Emerson, Intel, and EPAM, where he held the position of Engineering Manager. At Motorola and Emerson, he worked on embedded system projects for mobile devices and telecommunication infrastructures. He is now an engineering manager at EPAM, working with a team to deliver digital solutions for diverse clients.
Read more about Roger Ye

Right arrow

Preface

.NET MAUI is a cross-platform technology developed by Microsoft. The inaugural edition of this book was authored using .NET 6. However, this second edition coincides with the diverse improvements initiated with the release of .NET 8. The latest .NET MAUI release predominantly seeks to enhance code quality. Simultaneously, updates have been made to the development environment that supports iOS and Android, upgrading to Xcode 15 and Android API 34 respectively.

The improvements targeted are concentrated on a range of vital aspects, such as rectifying memory leaks, refining UI controls, instituting platform-specific fixes, and optimizing performance. The goal of these enhancements is to fortify memory management, escalate application stability, and polish the consistency of user experiences across varying platforms, thereby augmenting the overall application performance and responsiveness. With a focus on these components, I strive to provide you with an exhaustive understanding of the latest advancements in .NET MAUI technology.

Despite the broad array of cross-platform programming options available today, including Flutter and React Native, .NET MAUI stands out due to its unique features that should be considered when opting for a cross-platform solution.

One significant advantage of .NET MAUI is its single project structure, a marked improvement over Xamarin.Forms. This streamlined structure enhances various areas, such as:

  • Improving debugging and testing: With a single project structure, it’s possible to select and debug multiple targets within the same project, eliminating the need to switch between different projects for varied targets.
  • Sharing resources: Traditionally, in Xamarin, resources had to be managed individually for each platform. However, .NET MAUI has improved this aspect by enabling the sharing of the majority of resources across platforms, including fonts, images, icons, etc.
  • Simplified configuration: By utilizing a singular app manifest for most tasks, it is no longer necessary to separately manage platform configuration files such as AndroidManifest.xml, Info.plist or Package.appxmanifest.

In contrast, to access native device features in Flutter or React Native, you must rely on Flutter plugins or React Native Modules, which in turn rely on the developer community or require personal development. Furthermore, these interfaces are developer-designed and thus lack standardization. Thankfully, Microsoft has standardized APIs for most often used native device features as part of .NET MAUI’s release.

.NET MAUI facilitates application development using a traditional XAML-based UI or a Blazor-based UI in Blazor Hybrid apps, furthering opportunities for advanced code reuse. This advantage is particularly valuable for projects encompassing web and mobile apps, as it allows the sharing of user interface design and source code.

As .NET MAUI is now part of the .NET platform releases, we can always have access to the latest .NET platform and C# language features with every .NET release. This inclusion enables the use of advanced features like .NET generic hosting, dependency injection, and the MVVM Toolkit, among others.

In this book, I will guide you through my journey in .NET MAUI development using an open-source app I engineered. Both .NET MAUI and .NET platform features will be thoroughly explored throughout this edition.

Who this book is for

This book is primarily intended for front-end developers or native app developers who are interested in delving into cross-platform programming technology. It assumes that readers possess knowledge of C# programming or any object-oriented programming language akin to C#.

What this book covers

Part 1, Exploring .NET MAUI

Chapter 1, Getting Started with .NET MAUI, provides an introductory overview of cross-platform technologies. As part of this introduction, .NET MAUI is compared with other cross-platform technologies to highlight its unique features. Additionally, this chapter guides you through the process of setting up a .NET MAUI development environment. By reading this chapter, you’ll gain a broad understanding of cross-platform technologies that will assist you in selecting the most suitable option for your project.

Chapter 2, Building Our First .NET MAUI App, walks you through the process of setting up a new project, which will serve as the foundation for the development work presented in this book. Additionally, this chapter expounds upon the .NET MAUI project structure and comprehensively discusses the application lifecycle. By the end of this chapter, you’ll have mastered how to create a new project and acquired basic debugging skills pertinent to a .NET MAUI application.

Chapter 3, User Interface Design with XAML, introduces you to the concept of user interface design using XAML. This chapter explores the basic understanding of XAML along with .NET MAUI’s UI elements. Upon completion of this chapter, you’ll have gained the necessary proficiency to create your own user interface design.

Chapter 4, Exploring MVVM and Data Binding, introduces key topics in .NET MAUI app development, including the MVVM pattern and data binding. We will start with theory and then apply what we learn to the development work of the password management app. You will learn how to use data binding and apply it to the MVVM pattern.

Chapter 5, Navigation using .NET MAUI Shell and NavigationPage, explores the essential aspects of navigation in .NET MAUI app development. This includes topics such as the utilization of .NET MAUI Shell and NavigationPage for efficient navigation. The chapter begins with a theoretical overview and then transitions into practical use cases, specifically focusing on the development of a password management app. By the end of this chapter, you will have a robust understanding of how to effectively implement navigation within your .NET MAUI apps.

Chapter 6, Software Design with Dependency Injection, delves into design principles, specifically providing an overview of SOLID design principles. Subsequently, the chapter elucidates the use of dependency injection in .NET MAUI and incorporates this technique into our app development process. By the end of this chapter, you will not only have a broad understanding of SOLID design principles, but also a detailed understanding of dependency injection.

Chapter 7, Using Platform-Specific Features, covers sophisticated topics related to the utilization of platform-specific functionalities in .NET MAUI development. This chapter will guide you through the fundamental steps involved in implementing platform-specific code. This knowledge will be further cemented as you delve deeper into developing platform-specific features in our application.

Part 2, Implementing .NET MAUI Blazor

Chapter 8, Introducing Blazor Hybrid App Development, introduces the concept of developing applications using .NET MAUI Blazor. This chapter guides you through creating a new Blazor Hybrid app and provides instructions on converting a .NET MAUI XAML app to a .NET MAUI Blazor Hybrid app.

The knowledge you’ll acquire includes understanding the basic environment setup and Razor syntax that’s fundamental to .NET MAUI Blazor application development.

Chapter 9, Understanding Blazor Routing and Layout, focuses on the layout and routing aspects of a Blazor Hybrid app. This chapter provides insight into the setup process of the router and usage of layout components. By the end of this chapter, you’ll understand how to design a layout and set up routing for your application.

Chapter 10, Implementing Razor Components, delves into the concept of Razor components and the usage of data binding within them. This chapter will teach you how to create a Razor class library and guide you in refining existing Razor code to craft reusable Razor components. By the end of this chapter, you’ll have a practical understanding of how to effectively implement Razor components.

Part 3, Testing and Deployment

Chapter 11, Developing Unit Tests, introduces you to the unit test framework available for .NET MAUI. This chapter will teach you how to utilize xUnit and bUnit to develop effective unit test cases. Additionally, you will learn how to construct unit test cases for .NET classes as well as how to create unit test cases specifically for Razor components using bUnit.

Chapter 12, Deploying and Publishing in App Stores, discusses the procedure for preparing application packages for app stores and setting up a CI/CD workflow using GitHub Actions. This chapter provides insight into creating packages suitable for Google Play, Apple Store, and the Microsoft Store. Additionally, you will learn how to automate the package creation process using GitHub Actions, streamlining your publication efforts.

To get the most out of this book

After completing the first chapter, you can choose to proceed with Part 1 or jump to Part 2. The first part of this book delves into the development of a classic .NET MAUI app utilizing XAML UI. In contrast, the second part introduces Blazor Hybrid app development, a new concept in .NET MAUI. The last part of the book focuses on unit test and deployment strategies.

Please note that both Windows and macOS computers are required to build the projects discussed in this book. We’ll be using Visual Studio 2022 and .NET 8 SDK throughout. To build iOS and macOS targets on Windows, it is necessary to connect to a network-accessible Mac, as outlined in the Microsoft documentation provided: https://learn.microsoft.com/en-us/dotnet/maui/ios/pair-to-mac.

Since Visual Studio for Mac is scheduled for retirement by August 31, 2024, you may install .NET SDK and Visual Studio Code to replace it on Mac.

Software/hardware covered in the book

OS requirements

Visual Studio 2022

Windows

Visual Studio Code with .NET SDK

macOS

Download the example code files

You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/.NET-MAUI-Cross-Platform-Application-Development-Second-edition. If there’s an update to the code, it will be updated in the GitHub repository.

My working repository is https://github.com/shugaoye/PassXYZ.Vault2.

I will update the source code in my working repository first and then push the commits to Packt repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots and diagrams used in this book. You can download it here: https://packt.link/gbp/9781835080597.

Conventions used

There are a number of text conventions used throughout this book.

Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: “The return value of CreateMauiApp is a MauiApp instance, which is the entry point of our app.”

A block of code is set as follows:

private async Task<bool> UpdateItemAsync(string key, 
string value)
{
  if (listGroupItem == null) return false;
  if (string.IsNullOrEmpty(key) || 
      string.IsNullOrEmpty(value)) 
    return false;
  listGroupItem.Name = key;
  listGroupItem.Notes = value;
  if (_isNewItem) {...}
  else {...}
  StateHasChanged();
  return true;
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

Image image = new Image {
    BackgroundColor = Color.FromHex("#D1D1D1")
};
image.Source = new FontImageSource {
    Glyph = "\uf007",
    FontFamily = "FontAwesomeRegular",
    Size = 32
};

Any command-line input or output is written as follows:

git clone -b chapter09
https://github.com/PacktPublishing/Modern-Cross-Platform-Application-Development-with-.NET-MAUI PassXYZ.Vault2

Bold: Indicates a new term, an important word, or words that you see onscreen. For instance, words in menus or dialog boxes appear in bold. Here is an example: “Launch Visual Studio 2022 and select Create a new project on the startup screen.”

Tips

Appear like this.

Important notes

Appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: Email feedback@packtpub.com, and mention the book’s title in the subject of your message. If you have questions about any aspect of this book, please email us at questions@packtpub.com.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book we would be grateful if you would report this to us. Please visit, http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at copyright@packtpub.com with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit http://authors.packtpub.com.

Share your thoughts

Once you’ve read .NET MAUI Cross-Platform Application Development, Second Edition, we’d love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.

Your review is important to us and the tech community and will help us make sure we’re delivering excellent quality content.

Download a free PDF copy of this book

Thanks for purchasing this book!

Do you like to read on the go but are unable to carry your print books everywhere?

Is your eBook purchase not compatible with the device of your choice?

Don’t worry, now with every Packt book you get a DRM-free PDF version of that book at no cost.

Read anywhere, any place, on any device. Search, copy, and paste code from your favorite technical books directly into your application. 

The perks don’t stop there, you can get exclusive access to discounts, newsletters, and great free content in your inbox daily

Follow these simple steps to get the benefits:

  1. Scan the QR code or visit the link below
Qr code  Description automatically generated

https://packt.link/free-ebook/9781835080597

  1. Submit your proof of purchase
  2. That’s it! We’ll send your free PDF and other benefits to your email directly
lock icon
The rest of the chapter is locked
You have been reading a chapter from
.NET MAUI Cross-Platform Application Development - Second Edition
Published in: Mar 2024Publisher: PacktISBN-13: 9781835080597
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Roger Ye

Roger Ye is an embedded system programmer who has great interest in virtualization, Android, and cross-platform technologies. His professional experience includes working with major companies like Motorola, Emerson, Intel, and EPAM, where he held the position of Engineering Manager. At Motorola and Emerson, he worked on embedded system projects for mobile devices and telecommunication infrastructures. He is now an engineering manager at EPAM, working with a team to deliver digital solutions for diverse clients.
Read more about Roger Ye