Reader small image

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

Product typeBook
Published inNov 2023
Reading LevelBeginner
PublisherPackt
ISBN-139781805125006
Edition1st Edition
Languages
Right arrow
Author (1)
Pieter Nijs
Pieter Nijs
author image
Pieter Nijs

Pieter Nijs is a .NET consultant at Xebia in Belgium, with a keen interest in mobile and cloud development. He's been instrumental in diverse projects, from vast healthcare and telecom systems to compact LOB apps. Now, Pieter's exploring AI's potential to enhance customer projects innovatively. Passionate about technology, he actively experiments and shares knowledge as a conference speaker and trainer. Pieter has been awarded the Microsoft MVP Award since 2017, reflecting his unwavering passion and expertise in serving the community.
Read more about Pieter Nijs

Right arrow

Community Toolkits

In this chapter, we will explore some of the popular Community Toolkits that have been developed to assist developers in using data binding and the MVVM pattern more efficiently and effectively in .NET MAUI. These toolkits offer valuable components and utilities that can greatly enhance your development experience and help you build robust and maintainable applications. There are numerous large and small frameworks or toolkits that facilitate data binding and the application of the MVVM pattern in your projects. Some of them have a significant overall impact on your code, while others are more focused on providing developers with a set of helpers or components that you typically rewrite for each new project.

Every existing toolkit or framework is the product of dedicated developers investing their time and expertise, and each one provides value to its users, whether or not it suits your particular coding style. In this book, I don’t want to favor any specific...

Technical requirements

Throughout this chapter, we will be updating some code from the Recipes! app. The updated code can be found on GitHub at https://github.com/PacktPublishing/MVVM-pattern-.NET-MAUI/tree/main/Chapter05 for reference and comparison.

The MVVM Toolkit

The MVVM Toolkit (CommunityToolkit.Mvvm) is a comprehensive library that’s designed to simplify and streamline the implementation of the MVVM pattern in your applications. Developed and maintained by the .NET community, this toolkit provides a robust set of framework-independent tools, components, and utilities that help you build applications using the MVVM pattern. It’s important to note that this toolkit isn’t .NET MAUI-specific; it’s UI framework-agnostic.

Here are some of the key features of the MVVM Toolkit:

  • ObservableObject: This class serves as a base class that implements the INotifyPropertyChanged interface, simplifying the process of raising the PropertyChanged event. Its SetProperty method streamlines setting property values and automatically raises the PropertyChanged event when needed. By using this class, developers can reduce the boilerplate code associated with checking for property updates and triggering the...

The .NET MAUI Community Toolkit

The .NET MAUI Community Toolkit is a collection of useful components, controls, and utilities designed to enhance the development experience with .NET MAUI. Although its primary focus is not on enabling or facilitating MVVM, the toolkit does provide features that can greatly assist developers in implementing the MVVM pattern in their .NET MAUI projects:

  • Behaviors: These are reusable pieces of functionality that can be attached to certain types of controls. By encapsulating code in behaviors, you can keep your views clean and easy to understand.
  • Converters: As we’ve seen before, converters help transform data from one type into another, making it easier to bind data from your ViewModel to your View. The toolkit has a lot of converters for a huge range of common scenarios.

There is much more to the .NET MAUI Community Toolkit, but in the context of MVVM, these are the relevant bits. Please note that this is a toolkit that should...

Contributing to the community

As we wrap up this chapter, it’s important to recognize that these third-party toolkits and frameworks are, at their core, community contributions. They’re the result of someone else’s hard work, thought, and passion. All this code is accessible to you on platforms such as GitHub, and it’s maintained by community-minded individuals who are always open to suggestions, improvements, and bug reports.

Remember, contributing to the community isn’t limited to creating a new project or toolkit of your own. It can be as simple as reporting a bug, suggesting a feature, or even making a small code improvement on an open source project. This open source ethos is one of the key strengths of the .NET ecosystem.

So, if you’re using these frameworks and see something that can be improved or a bug that needs fixing, don’t hesitate to contribute. By doing so, you’ll not only improve the tool for yourself but...

Summary

To summarize, both the MVVM Toolkit and .NET MAUI Community Toolkit offer a comprehensive collection of components that facilitate the implementation of the MVVM pattern in your applications. By using these toolkits, you can avoid the need to build everything from scratch or reinvent existing solutions, ultimately saving time and effort, and allowing you to focus on building your application.

Throughout the rest of the code samples in this book, we’ll be using the MVVM Toolkit and make use of classes such as ObservableObject and RelayCommand. These classes are quite straightforward to understand. Even if you choose not to use this toolkit, you should still find the code samples clear and comprehensible as the underlying concepts are not overly complex.

Further reading

To learn more about the topics that were covered in this chapter, take a look at the following resources:

lock icon
The rest of the chapter is locked
You have been reading a chapter from
The MVVM Pattern in .NET MAUI
Published in: Nov 2023Publisher: PacktISBN-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.
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 AU $19.99/month. Cancel anytime

Author (1)

author image
Pieter Nijs

Pieter Nijs is a .NET consultant at Xebia in Belgium, with a keen interest in mobile and cloud development. He's been instrumental in diverse projects, from vast healthcare and telecom systems to compact LOB apps. Now, Pieter's exploring AI's potential to enhance customer projects innovatively. Passionate about technology, he actively experiments and shares knowledge as a conference speaker and trainer. Pieter has been awarded the Microsoft MVP Award since 2017, reflecting his unwavering passion and expertise in serving the community.
Read more about Pieter Nijs