
The MVVM Pattern in .NET MAUI
Description
Alles über E-Books | Antworten auf Fragen rund um E-Books, Kopierschutz und Dateiformate finden Sie in unserem Info- & Hilfebereich.
- Gain insights into.NET MAUI's MVVM-enabling components and effectively apply them with hands-on examples
- Learn data binding, navigation, and testable code techniques to create dynamic, accessible, and localized apps
- Purchase of the print or Kindle book includes a free PDF eBook
Book DescriptionIn today's fast-paced world of modern software development, teams need to be efficient, productive, and capable of rapidly adapting to changes to deliver high-quality products, making it crucial for developers to write maintainable and easy-to-test code. The MVVM Pattern in.NET MAUI helps you to thoroughly explore the Model-View-View Model (MVVM) design pattern. The chapters show you how this pattern helps in structuring code to embrace the separation of concerns, allowing for loosely coupled user interface and application logic, which ultimately empowers you to write more robust, maintainable, and testable code. The book also highlights.NET MAUI's capabilities and features, and enables you to delve into the essential components within the framework that facilitate the application of the MVVM pattern. With the help of a sample application, this definitive guide takes a hands-on approach to walk you through both the essential and advanced usages of the MVVM pattern to ensure that you successfully apply the practical aspects of the pattern to your.NET MAUI projects. By the end of this book, you'll have gained a comprehensive understanding of the MVVM design pattern and its relevance in the context of.NET MAUI, as well as developed the skills needed to successfully apply it in practice.What you will learn - Gain a thorough understanding of the MVVM design pattern
- Get to grips with the components that enable MVVM in.NET MAUI
- Apply the MVVM pattern in practice within.NET MAUI
- Become proficient in data binding in.NET MAUI
- Discover how to navigate from within a view model
- Find out how to effectively write testable code and unit tests
Who this book is forThis book is for developers with experience in C# and basic knowledge of.NET MAUI or Xamarin.Forms who are looking to create cross-platform applications with.NET MAUI and leverage the MVVM pattern. Through practical examples and clear explanations, this book helps both newcomers and experienced developers master the application of MVVM principles within.NET MAUI projects.
All prices
More details
Other editions
Additional editions

Content
- Cover
- Copyright
- Foreword
- Contributors
- Table of Contents
- Preface
- Part 1: Key Concepts and Components
- Chapter 1: What Is the MVVM Design Pattern?
- Technical requirements
- Looking at MVVM's core components
- Model
- View
- ViewModel
- Commands
- Data binding
- Separation of concerns matters
- Maintainability
- Testability
- MVVM in action
- The code-behind approach
- Using MVVM
- Common misconceptions about MVVM
- There should be no code in the code-behind
- The Model should exclusively be a DTO, a domain entity, or a POCO
- The View and the ViewModel should not know each other
- MVVM is too complex and used only for large applications
- Summary
- Chapter 2: What is .NET MAUI?
- Technical requirements
- .NET MAUI in a nutshell
- Reminiscent of Xamarin.Forms
- Cross-platform UI and more
- How does it work?
- Native apps with .NET
- .NET MAUI, another abstraction layer
- Creating your first .NET MAUI app
- Setting up your machine
- Hello "Recipes!" app
- Summary
- Further reading
- Chapter 3: Data Binding Building Blocks in .NET MAUI
- Technical requirements
- Key components for data binding
- Elements of data binding
- BindableObject
- BindableProperty
- BindingContext
- Data binding in practice
- Binding modes and the INotifyPropertyChanged interface
- Binding modes in .NET MAUI
- INofityPropertyChanged
- Different binding modes in action
- Handling interactions with the ICommand interface
- The ICommand interface
- Putting it into action
- Summary
- Further reading
- Chapter 4: Data Binding in .NET MAUI
- Technical requirements
- ValueConverters and StringFormat
- Creating and using ValueConverters
- Fallbacks
- TargetNullValue
- FallbackValue
- Element and relative binding
- Element binding
- Relative binding
- Multi-bindings
- Multi-binding StringFormat
- IMultiValueConverter
- Compiled bindings
- Summary
- Further reading
- Chapter 5: Community Toolkits
- Technical requirements
- The MVVM Toolkit
- ObservableObject
- RelayCommand
- Source Generators
- The .NET MAUI Community Toolkit
- Converters
- Behaviors
- Other popular frameworks
- Contributing to the community
- Summary
- Further reading
- Chapter 6: Working with Collections
- Technical requirements
- Using BindableLayout
- What to show and how to show it
- Dynamically choosing a DataTemplate at runtime
- The ICollectionChanged interface
- The ICollectionChanged interface and binding modes
- Using the ObservableCollection
- Working with CollectionView
- Displaying grouped data
- Selecting items
- Incrementally loading data
- Other common interactions
- Summary
- Further reading
- Part 2: Building a .NET MAUI App Using MVVM
- Chapter 7: Dependency Injection and Messaging
- Technical requirements
- Inversion of Control through Dependency Injection
- Dependency Injection
- Registering, resolving, and injecting services
- Registering services
- Resolving and injecting services
- Applying Dependency Injection
- Messaging
- WeakReferenceMessenger
- Summary
- Further reading
- Chapter 8: Navigation in MVVM
- Technical requirements
- About .NET MAUI Shell
- Setting up Shell
- Routing
- Supporting Dependency Injection
- Setting up navigation in a .NET MAUI Shell app
- Creating an INavigationService interface
- Creating and using a NavigationService interface
- Passing parameters
- Hooking into navigation
- Setting up navigation without .NET MAUI Shell
- Passing results back
- Summary
- Further reading
- Chapter 9: Handling User Input and Validation
- Technical requirements
- Implementing input validation on ViewModels
- Using the ObservableValidator
- Visualizing validation errors with triggers
- Prompts and alerts
- Confirming or canceling navigation
- Summary
- Further reading
- Chapter 10: Working with Remote Data
- Technical requirements
- Revisiting the model architecture
- Updates to the codebase
- Always return a result
- Adding repository interfaces
- API communication with Refit
- Getting started with Refit
- Creating API interfaces
- Integrating Refit
- API communication from ViewModels
- Showing a loading indicator
- Handling failures
- Summary
- Further reading
- Part 3: Mastering MVVM Development
- Chapter 11: Creating MVVM-Friendly Controls
- Technical requirements
- Building a custom control with bindable properties
- Implementing FavoriteControl
- Animating state changes
- Enabling interactions on custom controls
- User actions and reflecting state
- Adding command-based interactions
- Working with control templates
- Accessing elements from a template
- Summary
- Further reading
- Chapter 12: Localization with MVVM
- Technical requirements
- Working with cultures, resource files, and localization
- Getting the user's culture
- Setting a different culture
- Displaying formatted data
- What are Resources Files?
- Getting localized resources on the screen
- Looking at a localization solution for MVVM
- The Localization project
- The Localization.Maui project
- Using the LocalizedResourcesProvider and LocalizationManager
- Using a custom Translate markup extension
- Fetching localized data from APIs
- Summary
- Further reading
- Chapter 13: Unit Testing
- Technical requirements
- The importance of unit testing
- Setting up a unit test project
- Creating a unit test project
- Creating unit tests
- Looking at data-driven tests
- Generating data with Bogus
- Mocking dependencies with Moq
- Applying mocking in our ViewModel tests
- Thin UI, deep tests
- Testing MAUI-specific code
- Summary
- Further reading
- Chapter 14: Troubleshooting and Debugging Tips
- Technical requirements
- Common data binding issues
- Checking the Output and XAML Binding Failures window
- Debugging with a DoNothingConverter
- Troubleshooting collections
- The data binding pitfall on Behaviors
- Services and Dependency Injection pitfalls
- Unable to resolve service for type
- No parameterless constructor defined for type
- Incorrect service registration
- Frequent custom control and converter problems
- Troubleshooting bindable properties
- Binding to the BindingContext
- Value converter issues
- Summary
- Further reading
- Index
- Other Books You May Enjoy
System requirements
File format: ePUB
Copy protection: Adobe-DRM (Digital Rights Management)
System requirements:
- Computer (Windows; MacOS X; Linux): Install the free reader Adobe Digital Editions prior to download (see eBook Help).
- Tablet/smartphone (Android; iOS): Install the free app Adobe Digital Editions or the app PocketBook before downloading (see eBook Help).
- E-reader: Bookeen, Kobo, Pocketbook, Sony, Tolino and many more (not Kindle).
The file format ePub works well for novels and non-fiction books – i.e., „flowing” text without complex layout. On an e-reader or smartphone, line and page breaks automatically adjust to fit the small displays.
This eBook uses Adobe-DRM, a „hard” copy protection. If the necessary requirements are not met, unfortunately you will not be able to open the eBook. You will therefore need to prepare your reading hardware before downloading.
Please note: We strongly recommend that you authorise using your personal Adobe ID after installation of any reading software.
For more information, see our ebook Help page.
File format: ePUB
Copy protection: without DRM (Digital Rights Management)
System requirements:
- Computer (Windows; MacOS X; Linux): Use a reader that can handle the file format ePUB, such as Adobe Digital Editions or FBReader – both free (see eBook Help).
- Tablet/Smartphone (Android; iOS): Install the free app Adobe Digital Editions or the app PocketBook (see eBook Help).
- E-reader: Bookeen, Kobo, Pocketbook, Sony, Tolino and many more (not Kindle).
The file format ePUB works well for novels and non-fiction books – i.e., 'flowing' text without complex layout. On an e-reader or smartphone, line and page breaks automatically adjust to fit the small displays.
This eBook does not use copy protection or Digital Rights Management
For more information, see our eBook Help page.