The MVVM Pattern in . NET MAUI The Definitive Guide to Essential Patterns, Best Practices, and Techniques for Cross-Platform App Development
Gain an in-depth understanding of MVVM and .NET MAUI and learn how to effectively apply the MVVM design pattern with the help of this practical guide Key Features Get to grips with the principles and benefits of the Model-View-ViewModel design pattern Gain insights into .NET MAUI's MVVM-enablin...
Otros Autores: | , |
---|---|
Formato: | Libro electrónico |
Idioma: | Inglés |
Publicado: |
Birmingham, England :
Packt Publishing
[2023]
|
Edición: | First edition |
Materias: | |
Ver en Biblioteca Universitat Ramon Llull: | https://discovery.url.edu/permalink/34CSUC_URL/1im36ta/alma991009785405906719 |
Tabla de Contenidos:
- 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.