This repository was archived by the owner on Feb 25, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Feb 25, 2026. It is now read-only.
[Feature] Microsoft.Toolkit.Mvvm package (Preview 5) #3428
Copy link
Copy link
Closed
Labels
.NETComponents which are .NET based (non UWP specific)Components which are .NET based (non UWP specific)feature request 📬A request for new changes to improve functionalityA request for new changes to improve functionalityopen discussion ☎️
Milestone
Description
Overview
This issue is meant to be used to track all the feature requests and discussions regarding API changes or other tweaks for the Microsoft.Toolkit.Mvvm package, which was introduced with #3230 and recently announced. 🎉
Find initial docs and samples here at https://aka.ms/mvvmtoolkit.
Key Tenants
- Platform and Runtime Independent - .NET Standard 2.0 🚀 (UI Framework Agnostic)
- Simple to pick-up and use - No strict requirements on Application structure or coding-paradigms (outside of 'MVVM'ness) i.e. flexible usage
- À la carte - Developer able to choose the components they wish to leverage
- Reference Implementation - Lean and performant, provides compliments to interfaces and paradigms hinted at in the Base-Class Library, but without provided implementations.
If you want more info on the package, you're welcome to browse our samples and preview documentation (here), watch the initial presentation by @michael-hawker and I (here) or watch Michael's presentation during the UNO Conf (here).
Tracking changes so far
Will be updating this list with all the current (work in progress) changes that are being included into a PR.
Preview 5 (#3562)
- Added
ObservableValidator.ClearErrorsmethod - Added
ObservableValidator.ValidatePropertymethod - Added
ObservableValidator.ValidateAllPropertiesmethod - Added generic
ObservableValidator.GetErrorsmethod - Speed/memory optimizations to
WeakReferenceMessengeron .NET Standard 2.0
Preview 4 (#3527)
- Reintroduced
Iocclass (see docs) - Added new
ObservableObject.OnPropertyChanged(PropertyChangedEventArgs)overload - Added new
ObservableObject.OnPropertyChanging(PropertyChangingEventArgs)overload - The
OnPropertyChangedandOnPropertyChangingoverloads with astringparam are no longer virtual - Added notification support to
IAsyncRelayCommand.CanBeCanceledproperty - Improved notification logic for other
IAsyncRelayCommandproperties - Added notification support to
ObservableValidator.HasErrorsproperty - Added new
TrySetPropertymethods toObservableValidator - Minor performance/memory usage improvements and bug fixes
Preview 3 (shipped!) 🚀
ComponentModel, Input, DependencyInjection (#3429)
- New
ObservableValidatorclass forINotifyDataErrorInfo - Changed
SetPropertyAndNotifyOnCompletionsignature (7-14x faster, 60% memory usage reduction) - Changed signature of APIs, ditched
Expression<Func<T>>args - Added new
SetProperty<T, TModel>overload to allow stateless delegates and better performance - Added cancelation support to
AsyncRelayCommandtypes (and interfaces) - Improved XML docs with info about exceptions being thrown by the various APIs
- Removed
Iocclass andMicrosoft.Extensions.DependencyInjectiondependency
Messenger (#3424)
- Added a new
WeakReferenceMessengertype - Renamed
MessengertoStrongReferenceMessenger - Memory usage and performance improvements to
StrongReferenceMessenger - Changed
IMessenger.Registersignature to remove closures (35% memory usage reduction, nothiscaptured) - Added
IMessenger.CleanupAPI to help with extensibility - Changed default messenger for
ObservableRecipienttoWeakReferenceMessenger
Reacted by Tim, Borja Domínguez, Mrxx99, Marina Sundström, Laurent Kempé, Gino Messmer, Chris Bold and Arlo
Reacted by Tim, Mrxx99, Rao Hammas, Marina Sundström and Laurent Kempé
Metadata
Metadata
Assignees
Labels
.NETComponents which are .NET based (non UWP specific)Components which are .NET based (non UWP specific)feature request 📬A request for new changes to improve functionalityA request for new changes to improve functionalityopen discussion ☎️
Activity
Sergio0694 commentedon Aug 19, 2020
Posting an update here regarding the changes to the
SetPropertyAndNotifyOnCompletionmethod.The signature now has a custom delegate instead of the
ref+Expression<Func<T>>pair, which gives us:Code changes:
And some benchmarks:
Sergio0694 commentedon Aug 23, 2020
Hey @nanney54, let's continue here from your original comment in the issue for the Preview1.
I've come up with a solution I liked to add cancellation support to the async commands, so this new feature should be available in the next preview of the MVVM Toolkit, and of course you can also try it out already through the CI preview build 😄
The changes were added in 06cc520, here's the new
IAsyncRelayCommandinterface:Both
AsyncRelayCommandandAsyncRelayCommand<T>now include additional constructors taking aFunc<CancellationToken, Task>delegate, so that you can also wrap asynchronous methods using the token parameter to monitor whether a cancellation has been requested. The commands will take of creating and handling those tokens, so you'll just need to use thatCancelmethod if you want to request a cancellation, and that request will be relayed to the wrapped method through that token. If you just wrap a method taking no token, the behavior is unchanged compared to commands today.Here's a small example:
Let us know what you think! 😊
nanney54 commentedon Aug 25, 2020
It was fast ! did you have a git stash ready on your PC before my post ? 😁
30 remaining items
Insire commentedon Nov 21, 2020
I recently found out that this is going to be a thing and so i checked out the most recent public preview 4.
I don't really have complains and like what i see, how ever i'd like to see 2 things added, if possible:
OnChangedcallback inObservableObject.SetProperty, but i'm missing aOnChangingcallback in the same method. I'm aware that i can achieve similar funcionality by subscribing to the corresponding eventhandler that comes with the class. However having it there by default would be nice.IMessengerimplementations have ways to clean up any resources. I'd like to be able to clean them with something that implementsIDisposable, so that it neatly integrates with existing code.cirrusone commentedon Dec 29, 2020
Are you able to make both
ObservableObjectandObservableRecipientinterfaces as well? It's sometimes difficult to use these due to multiple inheritance so havingIObservableObjectandIObservableRecipientis much easier.Sergio0694 commentedon Jan 22, 2021
The new update for the MVVM Toolkit is ready for review now, posting an update here for those interested.
Other than the general improvements and tweaks you can see in the commits and in the first post here, this new PR includes a number of additions for the
ObservableValidatorclass (ie. ourINotifyDataErrorInfoimplementation), with changes that have been requested in a number of issues (eg. microsoft/microsoft-ui-xaml#179 and #3665), as well as being discussed on Discord and other channels. I hope with the updated API surface, this class will be a solid base type for developers writing validation forms 😄For starters, here's the complete API breakdown for the
ObservableValidatorclass (updated to a3c2f63):In particular, the additions from #3562 include:
ValidateAllProperties, which automatically performs validation on all the public properties with validation attributes on the current viewmodel, and updates the errors for all of them, raises the necessary events, etc. Essentially, you can call this method before submitting a form, and it'll automatically perfom the validation on the entire model.ValidateProperty, which performs manual validation on a property. This can be useful when dealing with properties whose validation state depends on other properties, so that you can trigger validation when the other value changes (see [Feature] The new MVVM-Library should allow to run validation manually #3665).ClearErrors, which clears errors either from a specific property, or for the entire entity (similar behavior toGetErrors).cc. @michael-hawker @timunie @thomasclaudiushuber @stevenbrix
[Feature] Microsoft.Toolkit.Mvvm package (Preview 5) (#3562)
Sergio0694 commentedon Feb 13, 2021
The MVVM Toolkit Preview 5 is now merged and available in the preview Azure feed from master! 🚀
It features a much improved
ObservableValidatorclass and many other tweaks, optimizations and bug fixes.Thank you everyone for all the feedbacks throughout all these iterative previews, it's been super helpful and the MVVM Toolkit has improved a lot over time already! I'll keep an eye out for other possible minor tweaks to slip in before the first official release, but this is all looking really great so far - we're almost there! 🎉 🎉
mrlacey commentedon Feb 15, 2021
Please confirm where this is available from.
The wiki points to a MyGet feed that no longer exists (https://dotnet.myget.org/gallery/uwpcommunitytoolkit) and it appears that support for the use of MyGet was removed in place of using Azure DevOps.
The main Azure DevOps feed only lists preview4.
The Azure DevOps Pull Request feed has a version of this available but as version 7.0.0-build.840.g99bd68412a.
Have I missed something?
Is there a different feed that I should be using?
It seems misleading to say preview 5 is available in that it's not obvious how to get it and try it out.
Sergio0694 commentedon Feb 15, 2021
Where do you see that link mentioned? It might just be a leftover.
The new feeds for the preview packages are mentioned in this wiki page, and the one with the packages built from pushes/merges into master is this one: https://pkgs.dev.azure.com/dotnet/WindowsCommunityToolkit/_packaging/WindowsCommunityToolkit-MainLatest/nuget/v3/index.json.
I didn't say "Preview 5", I specifically said the "MVVM Toolkit Preview 5", to mean that the changes in my PR called "MVVM Toolkit Preview 5" are now merged and therefore available through CI packages. For instance, you can find those bits in the latest one, which is
v7.0.0-build.836.1(you can check the list of the recent published packages here). I probably should've phrased that sentence to make it clear I wasn't referring to an actual Preview release of the whole Toolkit, that's a fair point, I absolutely didn't mean to be misleding with my message 🙂Hope this clears things up! 😄
Panda-Sharp commentedon Feb 15, 2021
Yeah I think the origin of the misunderstanding is here:
"The MVVM Toolkit Preview 5 is now merged and available in the
preview MyGet feedfrom master! 🚀"mrlacey commentedon Feb 15, 2021
Yes, I didn't think there was a MyGet feed any more and so searched for
MyGetin the repo. It found references that I have now raised a PR to correct. (CommunityToolkit/WindowsCommunityToolkit-wiki#19)