Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
The MVVM Pattern in .NET MAUI

You're reading from  The MVVM Pattern in .NET MAUI

Product type Book
Published in Nov 2023
Publisher Packt
ISBN-13 9781805125006
Pages 386 pages
Edition 1st Edition
Languages
Author (1):
Pieter Nijs Pieter Nijs
Profile icon Pieter Nijs

Table of Contents (20) Chapters

Preface 1. Part 1: Key Concepts and Components
2. Chapter 1: What Is the MVVM Design Pattern? 3. Chapter 2: What is .NET MAUI? 4. Chapter 3: Data Binding Building Blocks in .NET MAUI 5. Chapter 4: Data Binding in .NET MAUI 6. Chapter 5: Community Toolkits 7. Chapter 6: Working with Collections 8. Part 2: Building a .NET MAUI App Using MVVM
9. Chapter 7: Dependency Injection, Services, and Messaging 10. Chapter 8: Navigation in MVVM 11. Chapter 9: Handling User Input and Validation 12. Chapter 10: Working with Remote Data 13. Part 3: Mastering MVVM Development
14. Chapter 11: Creating MVVM-Friendly Controls 15. Chapter 12: Localization with MVVM 16. Chapter 13: Unit Testing 17. Chapter 14: Troubleshooting and Debugging Tips 18. Index 19. Other Books You May Enjoy

Preface

In an era where software design patterns and frameworks are at the heart of robust application development, mastering the Model-View-ViewModel (MVVM) pattern becomes crucial for developers stepping into the domain of .NET MAUI. The MVVM Pattern in .NET MAUI: A definitive guide to essential patterns, best practices, and techniques, has been meticulously crafted to serve as a guide for developers eager to embark on this journey.

What sets this book apart is its laser focus on .NET MAUI. We don’t just talk about MVVM in general; we delve deep into its practical application within this specific framework. Even if you’re new to MVVM or just starting with .NET MAUI, this guide is crafted to be both accessible and enriching.

Our journey begins with an in-depth exploration of the MVVM design pattern and the core components of the .NET MAUI framework. As we progress, we’ll navigate through the intricacies of data binding, harnessing the power of community toolkits, and managing collections effectively. We’ll dive deeper to understand dependency injection, service patterns, and messaging, and you will learn about different methods of navigation, understand user input and validation, and master the techniques of working with remote data. The latter chapters guide you through creating MVVM-friendly controls, localizing your applications, and the pivotal aspect of unit testing.

From these fundamentals to advanced techniques, by the end of this journey, you’ll be fully equipped with the knowledge to integrate MVVM effectively into your .NET MAUI projects.

Welcome to your definitive guide!

Who this book is for

This book is tailored toward developers who aim to harness the power of the MVVM pattern within the context of .NET MAUI. Whether you’re an enthusiast beginning your journey with .NET MAUI or a seasoned professional aiming to up their game in both .NET MAUI and MVVM, this guide has got you covered.

While prior experience with .NET MAUI or Xamarin.Forms aren’t necessary, a foundational understanding of C# is essential. Developers familiar with C# will find the content approachable and structured to elevate their skills seamlessly to the wonderful worlds of .NET MAUI and MVVM.

From novices in the mobile application development arena to veterans seeking specialized knowledge in .NET MAUI’s MVVM implementation, this book serves as a comprehensive guide for all.

What this book covers

Chapter 1, The MVVM Design Pattern, provides an overview of the core components of the MVVM pattern, showing their roles and interplay. It illustrates the value of separating UI from logic for better testability and maintenance. It addresses common MVVM misconceptions and offers a foundational grasp of MVVM, regardless of specific technology.

Chapter 2, What Is .NET MAUI?, gives an overview of the overarching landscape of .NET MAUI, its pivotal features and advantages, and its architecture. It provides insights into .NET MAUI’s origins from Xamarin and Xamarin Forms, and its evolutionary journey.

Chapter 3, Data Binding Building Blocks in .NET MAUI, shows how data binding in .NET MAUI, a cornerstone for MVVM, is an essential part of .NET MAUI. This chapter unpacks the key principles, elements, and techniques underpinning this essential feature.

Chapter 4, Data Binding in .NET MAUI, builds upon the previous chapter but delves deeper into its intricacies and nuances, offering a comprehensive exploration of all the aspects of data binding in .NET MAUI.

Chapter 5, Community Toolkits, zeros in on two influential community toolkits: the MVVM Toolkit and the .NET MAUI Community Toolkit. It shows how these community-driven initiatives can amplify the effectiveness of MVVM in your .NET MAUI applications.

Chapter 6, Working with Collections, provides an overview of how to effectively display datasets using MVVM in .NET MAUI. From binding data and adapting to its changes to crafting data templates, this chapter offers an MVVM-centric guide to presenting data and facilitating user interactions with it.

Chapter 7, Dependency Injection, Services, and Messaging, illuminates the methods of aligning a ViewModel with a view via service registration and dependency injection. It highlights the nuances of injecting services into a ViewModel and facilitating seamless communication between ViewModels using messaging, all while upholding separation of concerns and enhancing testability.

Chapter 8, Navigation in .NET MAUI, is all about MVVM-based navigation. This chapter provides an overview of what .NET MAUI Shell is and its implications for navigation. It shows how to construct a navigation service tailored for both .NET MAUI apps that leverage Shell and apps that don’t.

Chapter 9, Handling User Input and Validation, shows how to effectively handle user input, from validating data at the ViewModel level, standard and custom validation rules, to prompting the user for confirmations or cancellations in the presence of unsaved changes.

Chapter 10, Working with Remote Data, shows how to work with remote data, introduces repositories for maintaining separation of concerns, and utilizes dependency injection. It illustrates how to use Refit for streamlined API interactions, and how to handle asynchronous tasks and their UI implications.

Chapter 11, Creating MVVM-Friendly Controls, dives into the creation of custom controls that are tailored for MVVM, supporting data binding and interactivity through commands.

Chapter 12, Localization with MVVM, provides an overview of the techniques to localize hardcoded labels within the app, and how to effectively fetch language-specific data from APIs.

Chapter 13, Unit Testing, shows how easy and essential unit testing is. It guides you through setting up a unit test project, generating data, mocking dependencies, and testing MAUI code.

Chapter 14, Troubleshooting and Debugging Tips, highlights common hiccups and their solutions. It shows typical issues and pitfalls concerning data binding, dependency injection, and building custom controls and converters.

To get the most out of this book

You will need to be familiar with the basics of C#.

Early on in the book, we’ll stipulate how to get your development environment up and running using Visual Studio 2022 or Visual Studio Code. The steps described in this book are based on Visual Studio, but everything that is explained and shown can also be done in any IDE that supports .NET MAUI.

If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book’s GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

Download the example code files

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

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

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: “RecipeDetailViewModel represents the details of a recipe. For now, it only contains a Title property, which we now give a hardcoded value of "Classic Caesar Salad".”

A block of code is set as follows:

<Grid ColumnDefinitions="*, Auto">
    <Label
        FontAttributes="Bold" FontSize="22"
        Text="{Binding Path=Title, Mode=OneTime}"
        VerticalOptions="Center" />
    <Image
        x:Name="favoriteIcon"
        Grid.Column="1" Margin="5"
        HeightRequest="35" Source="favorite.png"
        VerticalOptions="Center" WidthRequest="35">
    </Image>
</Grid>

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

private bool _hideAllergenInformation = true;
public bool HideAllergenInformation
{
    get => _hideAllergenInformation;
    set => SetProperty(ref _hideAllergenInformation, value);
}

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: “Right-click the Recipes.Client.Core project and select Add | New Folder and name it Messages. “

Tips or important notes

Appear like this.

Get in touch

Feedback from our readers is always welcome.

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

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 www.packtpub.com/support/errata and fill in the form.

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@packt.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 authors.packtpub.com.

Share Your Thoughts

Once you’ve read The MVVM pattern in .NET MAUI, 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

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

  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
Next Chapter arrow right
You have been reading a chapter from
The MVVM Pattern in .NET MAUI
Published in: Nov 2023 Publisher: Packt ISBN-13: 9781805125006
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.
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 AU $19.99/month. Cancel anytime}