.NET Community Toolkit 8.2 Adds Custom Attributes, Property Change Hooks, and MVVM Optimizations
Microsoft has introduced .NET Community Toolkit 8.2, continuing its focus on improving MVVM (model-view-viewmodel) development. This new release builds on the foundation of version 8.1, which had already enhanced MVVM features earlier in the year. Developers utilizing MVVM patterns will find the 8.2 update particularly helpful with a range of new improvements.
The .NET Community Toolkit provides a robust set of APIs and helpers for .NET developers, designed to be independent of any specific UI platform. As with previous versions, the toolkit’s source code is available on GitHub for community access and collaboration. One of the standout improvements in version 8.2 involves enhancements to the MVVM Toolkit, specifically around custom attributes.
In this release, custom attributes are now supported when using the [RelayCommand] attribute, giving developers more control over generated members. By leveraging the native field:
and property:
C# syntax, developers can better target custom attributes, providing finer control when using [RelayCommand] to generate commands in an MVVM pattern. This feature is especially useful in scenarios like JSON serialization, where certain properties may need to be explicitly ignored.
Another important addition to the MVVM Toolkit is the inclusion of two new property change hooks for all fields marked with [ObservableProperty]. In previous versions, the infrastructure for tracking changes to property values, such as old and new states, was limited. This meant developers had to write additional logic for scenarios like handling “selected item” properties in viewmodels. The new property change hooks solve this by allowing developers to inject custom logic directly into the old and new value transitions.
These new hooks make it easier to manage more complex state transitions in MVVM applications. For example, when a selected item changes, developers can now easily add logic to modify the state of both the old and new instances, reducing the amount of boilerplate code needed.
This release also includes several optimizations to MVVM source generators, further improving the overall performance of applications built using the MVVM Toolkit. These optimizations are aimed at streamlining code generation and enhancing the maintainability of larger, more complex projects.
Overall, .NET Community Toolkit 8.2 continues to make significant strides in empowering .NET developers to build cleaner, more efficient MVVM applications. The added flexibility around custom attributes and improved property change tracking will be particularly beneficial in projects that require advanced state management and serialization capabilities.