Using the #mvvmlight DispatcherHelper in your .NET Standard libraries

.NET, .NET Standard, MVVM, Technical stuff, Universal Windows Platform UWP, Windows 10, WPF, XAML
See comments

You might have heard that MVVM Light is now available as a .NET Standard 1.0 package, which means that you can use it in all your .NET Standard libraries (including 1.0, 1.4, 2.0 etc). Since .NET Standard is always backwards compatible, having MVVM Light running on .NET Standard 1.0 is quite convenient.

With .NET Standard, the incentive to use MVVM Light in even more applications is pretty huge, and with this the desire to use the DispatcherHelper to “translate” calls from a background thread into the UI thread of a UWP application, for instance. However as you might have already noticed, you cannot simply use the DispatcherHelper from within a .NET Standard library (nor from within a Portable Class Library for that matter). This is because the DispatcherHelper is a platform-specific component. In other words, the implementation for WPF is not compatible with the UWP or the Xamarin implementations. As a result, the DispatcherHelper class lives in the GalaSoft.MvvmLight.Platform DLL which gets added to your WPF, UWP or Xamarin applications, but NOT to your PCL or .NET Standard libraries…

The following article and sample propose a workaround. The article also details a few changes I want to add to MVVM Light to make it much easier to use DispatcherHelper in .NET Standard and Portable Class Libraries. Hopefully this will be useful!

Happy coding

Previous entry | Next blog entry

Comments for Using the #mvvmlight DispatcherHelper in your .NET Standard libraries