Explore 1.5M+ audiobooks & ebooks free for days

Only $12.99 CAD/month after trial. Cancel anytime.

.NET MAUI Cross-Platform Application Development: Build high-performance apps for Android, iOS, macOS, and Windows using XAML and Blazor with .NET 8
.NET MAUI Cross-Platform Application Development: Build high-performance apps for Android, iOS, macOS, and Windows using XAML and Blazor with .NET 8
.NET MAUI Cross-Platform Application Development: Build high-performance apps for Android, iOS, macOS, and Windows using XAML and Blazor with .NET 8
Ebook1,374 pages9 hours

.NET MAUI Cross-Platform Application Development: Build high-performance apps for Android, iOS, macOS, and Windows using XAML and Blazor with .NET 8

Rating: 0 out of 5 stars

()

Read preview
LanguageEnglish
PublisherPackt Publishing
Release dateMar 25, 2024
ISBN9781835082843
.NET MAUI Cross-Platform Application Development: Build high-performance apps for Android, iOS, macOS, and Windows using XAML and Blazor with .NET 8
Author

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.

Related to .NET MAUI Cross-Platform Application Development

Related ebooks

Programming For You

View More

Reviews for .NET MAUI Cross-Platform Application Development

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    .NET MAUI Cross-Platform Application Development - Roger Ye

    cover.png

    .NET MAUI Cross-Platform Application Development

    Second Edition

    Build high-performance apps for Android, iOS, macOS, and Windows using XAML and Blazor with .NET 8

    Roger Ye

    BIRMINGHAM—MUMBAI

    .NET MAUI Cross-Platform Application Development

    Second Edition

    Copyright © 2024 Packt Publishing

    All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

    Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

    Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

    Senior Publishing Product Manager: Larissa Pinto

    Acquisition Editor – Peer Reviews: Jane D’Souza

    Project Editor: Yamini Bhandari

    Content Development Editor: Matthew Davies

    Copy Editor: Safis Editing

    Technical Editor: Tejas Mhasvekar

    Proofreader: Safis Editing

    Indexer: Hemangini Bari

    Presentation Designer: Pranit Padwal

    Developer Relations Marketing Executive: Sohini Ghosh

    First published: January 2023

    Second edition: March 2024

    Production reference: 1190324

    Published by Packt Publishing Ltd.

    Grosvenor House

    11 St Paul’s Square

    Birmingham

    B3 1RB, UK.

    ISBN 978-1-83508-059-7

    www.packt.com

    Contributors

    About the author

    Roger Ye is a seasoned software engineering manager with expansive experience in the software industry. He began his professional journey working on embedded system development for notable companies such as Motorola, Emerson, and Intersil, during which he authored two books on the subject: Embedded Programming with Android and Android System Programming.

    In 2013, Roger moved to McAfee, where he assumed the role of software engineering manager. More recently, he served in a similar capacity at EPAM Systems, transitioning from system programming to application programming. His current interests revolve around .NET programming and Microsoft technologies; he dedicates himself to continuous learning and mastery in these areas.

    I would like to express my profound gratitude to the diligent team at Packt, who worked tirelessly alongside me to maintain our demanding schedule. I am deeply appreciative of my wife and daughter, whose unwavering support has been a beacon of strength for me throughout every endeavor.

    About the reviewers

    Rohit Vinod Kelkar is a software professional with over six years of experience working in various domains, with a focus on multi-stack development in cross-platform domains. He currently works for Globant as an engineer. His expertise includes full stack .NET development focused on Xamarin and MAUI, multiplatform application development using Flutter, and native iOS development with Swift and SwiftUI. On top of front-end development, he is enthusiastic about back-end technologies like Node .js and express stacks with MongoDB.

    I would like to thank Packt for reaching out and providing this opportunity to be a part of this book.

    Almir Vuk is an active Microsoft MVP and a senior software engineer with a primary focus on the .NET platform. He excels in crafting applications using C# and ASP.NET Core for back-end systems and .NET MAUI for mobile development. Some of the titles and awards that illustrate his career are Microsoft MVP, Xamarin Certified Mobile Developer, Microsoft Certified Solution Associate, and Microsoft Certified Trainer.

    A frequent speaker at Microsoft-related events and user group meetings, both regionally and internationally, he finds enjoyment in various pursuits during his free time. These include playing chess, reviewing technical books, writing blog posts, offering help on StackOverflow, contributing to open-source projects, and taking the role of an instructor at NGO programming-related events.

    Learn more on Discord

    Join our community’s Discord space for discussions with the author and other readers:

    https://packt.link/cross-platform-app

    Contents

    Preface

    Who this book is for

    What this book covers

    To get the most out of this book

    Get in touch

    Part 1: Exploring .NET MAUI

    Getting Started with .NET MAUI

    Overview of cross-platform and full stack technologies

    Native application

    Web application

    Backend services

    Managing development complexity

    Full stack development

    Cross-platform technologies

    Apache Cordova

    Ionic

    React Native

    Flutter

    .NET MAUI

    Analysis of cross-platform full stack solutions

    Comparison of .NET and JavaScript

    Exploring the .NET landscape

    .NET Framework

    Mono

    .NET Core

    .NET Standard and Portable Class Libraries

    Using Xamarin for cross-platform development

    Xamarin.Forms

    Xamarin.Essentials

    Comparing user interface design on different platforms

    Moving to .NET MAUI

    .NET MAUI Blazor apps

    Developing native apps using .NET

    What’s new in .NET 8 for .NET MAUI?

    Native AOT support for iOS-like platforms

    .NET MAUI extension of Visual Studio Code

    Development environment setup

    Using Visual Studio

    Installing .NET MAUI on Windows

    Installing .NET MAUI on macOS

    Visual Studio Code with the .NET MAUI extension

    Summary

    Further reading

    Building Our First .NET MAUI App

    Technical requirements

    Managing the source code in this book

    Download the source code in a compressed file

    Clone the source code per chapter

    Clone the source code from the main branch

    Setting up a new .NET MAUI project

    Creating a new project using Visual Studio

    Creating a new project using the dotnet command

    App startup and lifecycle

    Lifecycle management

    Subscribing to the Window lifecycle events

    Consuming the lifecycle override methods

    Configuring the resources

    App icon

    Splash screen

    Setting custom font icons

    Custom font setup

    Displaying font icons

    Building and debugging

    Windows

    Android

    iOS and macOS

    Building and testing the iOS target

    Building and testing the macOS target

    Migrating from Xamarin

    Migrating and reusing the Shell template from Xamarin.Forms

    Visual Studio project template

    Summary

    User Interface Design with XAML

    Technical requirements

    Creating a XAML page

    XAML syntax

    XML declaration

    Element

    Attribute

    XML and XAML namespaces

    Creating a new page using XAML

    Creating the same new page using C#

    XAML markup extensions

    Building a user interface

    Layouts

    StackLayout

    Grid

    FlexLayout

    AbsoluteLayout

    Views

    Label

    Image

    Editor

    Entry

    ListView

    Master-detail UI design

    Side-by-side

    Stacked

    Navigation in the master-detail UI design

    ItemDetailPage

    ItemsPage

    Supporting multiple languages – localization

    Creating a .resx file

    Localizing text

    Summary

    Further reading

    Exploring MVVM and Data Binding

    Technical requirements

    Understanding MVVM and MVC

    MVVM in PassXYZ.Vault

    Data binding

    Binding object

    Binding target

    Binding source

    Properties of a Binding object

    Source

    Binding mode

    Changing notifications in ViewModels

    .NET Community Toolkit

    How to use the MVVM Toolkit

    Improving the data model and service

    KPCLib

    Abstraction of PwGroup and PwEntry

    PassXYZLib

    Updating the model

    Updating the service

    Binding to collections

    Using custom views

    Summary

    Further reading

    Navigation Using .NET MAUI Shell and NavigationPage

    Technical requirements

    Implementing navigation

    INavigation interface and NavigationPage

    Using the navigation stack

    Manipulating the navigation stack

    Inserting a page

    Removing a page

    Using Shell

    Flyout

    Flyout items

    Menu items

    Tabs

    Shell navigation

    Registering absolute routes

    Registering relative routes

    Passing data to pages

    Improving our app

    Understanding the improved design

    Registering absolute routes and relative routes

    Model and services

    Implementation of IUserService

    Improving the login process

    Login view model

    Login UI

    Summary

    Software Design with Dependency Injection

    Technical requirements

    A brief overview of design principles

    Exploring types of design principles

    Don’t Repeat Yourself (DRY)

    Keep It Simple, Stupid (KISS)

    You Aren’t Gonna Need It (YAGNI)

    SOLID design principles

    Using design principles

    Implementing DI

    Lifetime management

    Configuring DI in .NET MAUI

    Constructor injection

    Method injection

    Property injection

    Replacing the mock data store

    Initializing the database

    Performing CRUD operations

    Adding an item

    Editing or deleting an item

    Summary

    Further reading

    Using Platform-Specific Features

    Technical requirements

    Implementing platform-specific code

    Conditional compilation

    Interfaces, partial class, and methods

    .NET MAUI/Xamarin plugins

    The evolution of .NET MAUI/Xamarin plugins

    The introduction of Plugin.Fingerprint

    Supporting fingerprint functionality using Plugin.Fingerprint

    Fingerprint settings

    Login using a fingerprint

    Customizing controls

    Overview of handlers

    Using HybridWebView

    Implementing MarkdownView

    Summary

    Further reading

    Part 2: Implementing .NET MAUI Blazor

    Introducing Blazor Hybrid App Development

    Technical requirements

    What is Blazor?

    Hosting models

    Blazor Server

    Blazor Wasm

    Blazor Hybrid

    Blazor Bindings

    What’s new in .NET 8 Blazor hosting models

    Project templates of .NET MAUI and Blazor apps

    Blazor apps

    .NET MAUI apps

    Creating a new .NET MAUI Blazor project

    Generating a .NET MAUI Blazor project with the dotnet command line

    Creating a .NET MAUI Blazor Hybrid App using Visual Studio on Windows

    Running the new project

    The startup code of the .NET MAUI Blazor Hybrid App

    Migrating to a .NET MAUI Blazor Hybrid App

    Understanding Razor syntax

    Code blocks in Razor

    Implicit Razor expressions

    Explicit Razor expressions

    Expression encoding

    Directives

    Directive attributes

    Creating a Razor component

    Redesigning the login page using a Razor component

    The Model-View-ViewModel (MVVM) pattern in Blazor

    Dependency injection in Blazor

    CSS isolation

    Summary

    Further reading

    Understanding Blazor Routing and Layout

    Technical requirements

    Understanding client-side routing

    Setting up BlazorWebView

    Setting up the Router component

    Defining routes

    Passing data using route parameters

    Navigating with NavigationManager

    Using Blazor layout components

    Applying a layout to a component

    Nesting layouts

    Implementing navigation elements

    Implementing a list view

    Adding a new item and navigating back

    Summary

    Implementing Razor Components

    Technical requirements

    Understanding Razor components

    Inheritance

    Creating a Razor class library

    Using static assets in the Razor class library

    Creating reusable Razor components

    Creating a base modal dialog component

    Data binding

    Component parameters

    Nested components

    Child content rendering

    Two-way data binding

    Binding with component parameters

    Communicating with cascading values and parameters

    Understanding the Razor component lifecycle

    SetParametersAsync

    OnInitialized and OnInitializedAsync

    OnParametersSet and OnParametersSetAsync

    ShouldRender

    OnAfterRender and OnAfterRenderAsync

    Implementing CRUD operations

    CRUD operations of items

    Adding a new item

    Editing or deleting an item

    CRUD operations of fields

    Refactoring Razor components

    Creating the Navbar component

    Creating a Dropdown component for the context menu

    Using templated components

    Creating a ListView component

    Using the ListView component

    Accessing a native API from Blazor Hybrid apps

    Summary

    Part 3: Testing and Deployment

    Developing Unit Tests

    Technical requirements

    Unit testing in .NET

    Setting up the unit test project

    Developing test cases for the model

    Sharing context between tests

    Sharing using a constructor

    Sharing using class fixtures

    Sharing using collection fixtures

    Mock .NET MAUI components

    Razor component testing using bUnit

    Changing the project configuration for bUnit

    Creating a bUnit test case

    Creating test cases in Razor files

    Using the RenderFragment delegate

    Testing Razor pages

    Summary

    Further reading

    Deploying and Publishing in App Stores

    Technical requirements

    Preparing application packages for publishing

    Preparing for publishing

    Publishing to Microsoft Store

    Publishing to Google Play Store

    Publishing to Apple’s App Store

    GitHub Actions

    Understanding GitHub Actions

    Workflows

    Events

    Jobs

    Runners

    Steps

    Summary

    Further reading

    Other Books You May Enjoy

    Index

    Landmarks

    Cover

    Index

    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.

    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

    [email protected]

    , 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

    [email protected]

    .

    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

    [email protected]

    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:

    Scan the QR code or visit the link below

    Qr code Description automatically generated

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

    Submit your proof of purchase

    That’s it! We’ll send your free PDF and other benefits to your email directly

    Part 1

    Exploring .NET MAUI

    In the first part of this book, we will delve into .NET MAUI programming. We will begin with an introduction to .NET MAUI and its predecessor, Xamarin.Forms. Following that, we will create a code base using the Visual Studio template for our application. Throughout this book, we will develop a password manager app called PassXYZ.Vault, building it step by step. During the app’s development, we will cover user interface design using XAML, the MVVM pattern, data binding, Shell, and dependency injection, among other topics.

    By the end of Part 1, we will have completed a fully functional password manager application. In this part, we’ll explore some of the important groundwork for this application, such as using the .NET Community Toolkit in the context of MVVM and data binding. This will enable you to build and implement applications that involve handling high volumes of data effectively.

    Part 1 includes the following chapters:

    Chapter 1, Getting Started with .NET MAUI

    Chapter 2, Building Our First .NET MAUI App

    Chapter 3, User Interface Design with XAML

    Chapter 4, Exploring MVVM and Data Binding

    Chapter 5, Navigation Using .NET MAUI Shell andNavigationPage

    Chapter 6, Software Design with Dependency Injection

    Chapter 7, Using Platform-Specific Features

    1

    Getting Started with .NET MAUI

    Since the release of .NET 5, Microsoft has been trying to unify different .NET implementations into one .NET release. .NET Multi-platform App UI (or .NET MAUI) is the effort to provide a unified cross-platform UI framework. We will learn how to use .NET MAUI to develop cross-platform applications in this book.

    The following is what we will cover in this chapter:

    Overview of cross-platform technologies

    Comparison of cross-platform technologies (.NET, Java, and JavaScript)

    .NET landscape and the history of Xamarin

    .NET MAUI features

    .NET MAUI Blazor apps

    What’s new in .NET 8 for .NET MAUI?

    Development environment setup

    If you’re new to .NET development, this chapter will help you to understand the .NET landscape. For Xamarin developers, many topics in this book may sound familiar; this chapter will give you an overview of what we will discuss in this book.

    Overview of cross-platform and full stack technologies

    .NET Multi-platform App UI, or .NET MAUI, is a cross-platform development framework from Microsoft for building apps that targets both mobile and desktop form factors on Android, iOS, macOS, Windows, and Tizen. It is one of a number of cross-platform frameworks available on the market.

    Before discussing cross-platform technologies, let’s review the scope of application development first. This review will help us to understand the various cross-platform frameworks better.

    Generally, software development can be divided into two categories – systems programming and application programming. Application programming aims to produce software that provides services to the user directly, whereas systems programming aims to produce software and software platforms that provide services to other software. In the .NET domain, the development of the .NET platform itself belongs to systems programming, whereas application development on top of the .NET platform belongs to application programming.

    Compared to systems programming, most software development demands are from application programming.

    Many business solutions fall under the category of application development. To understand why we choose a specific technology stack for a solution, it is essential to have an overview of all the technologies used in the entire solution. Once we have a clear understanding of the role cross-platform technologies play within the entire solution, we can better comprehend the technology we wish to select.

    Most of the development effort for business solutions consists of frontend and backend components. Frontend developers are responsible for the visible and interactive part of an application that users directly see, touch, and interact with. Typically, the frontend team focuses on developing web and native applications. On the other hand, backend development deals with server-side processing, data management, and the implementation of business logic within an application.

    Frontend and backend development involve different programming languages and frameworks. Sometimes, the same team may work on both frontend and backend development due to various reasons. In this case, we need a team who can work on full stack development.

    To classify application development by programming languages and frameworks, we have the below three categories.

    Native application

    By native application development, we usually refer to application development for a particular operating system. For desktop applications, it could involve Windows applications, macOS applications, or Linux applications. For mobile applications, it could involve Android or iOS.

    When we develop a native application, we may need to support multiple platforms (Windows, Linux, Android, macOS/iOS, etc.). To support multiple platforms, we need to use different programming languages, tools, and libraries to develop each of them individually.

    Web application

    Web application development has gone through several generations of evolution over the past few decades, from the Netscape browser with static web pages to today’s single-page application (SPA) using JavaScript frameworks (such as React and Angular). In web application development, JavaScript and various JavaScript-based frameworks dominate the market. In the .NET ecosystem, Blazor is trying to catch up in this area. We’ll learn more about Blazor in Chapter 8, Introducing Blazor Hybrid App Development.

    Backend services

    Both native applications and web applications typically require backend services to access business logic or a database. For backend development, there are various languages and frameworks available, including Java/Spring, .NET, Node.js, Ruby on Rails, and Python/Django. In many cases, native applications and web applications can share the same backend service. Java/Spring, ASP.NET, and Node.js are among the most popular choices for backend service developments.

    The selection of the technical stack for each category can significantly impact the complexity of a solution. In the next section, we will review and analyze solution complexity.

    Managing development complexity

    Building a complete solution usually requires a web app, a native app, and a backend service. Since web, native, and backend development use different programming languages and frameworks, we have to set up multiple teams to implement one solution. To manage the complexity of the development process, we need to manage the profile of the development team. The team profile can be managed according to two extreme cases/approaches. The simplest one is to set up one team that works on all stacks. The more complex one is to have separate teams for each stack. To successfully develop for all stacks using one team, the team must be a cross-platform full stack development team. Is it possible to have a cross-platform full stack team? Let’s review various scenarios for this in the next two sections.

    Full stack development

    Many people doubt whether it is good, or even possible, to set up a full stack team, but in fact, the earliest web development frameworks were full stack frameworks. If you had a chance to use Java/Thymeleaf or ASP.NET MVC, you will know that they are full stack frameworks. These frameworks use server-side rendering, so the implementation of the UI and business logic are all on the server side.

    The

    Enjoying the preview?
    Page 1 of 1