Announcing MVVM Light V5 for Windows and Xamarin
Here at the Xamarin Evolve conference in Atlanta, I just announced the immediate availability of MVVM Light V5. This version runs on the following platforms:
- Windows Presentation Foundation (3.5, 4, 4.5, 4.5.1)
- Silverlight (4 and 5)
- Windows Phone (7.1, 8, 8.1 Silverlight, 8.1 RT)
- Windows Store (8, 8.1)
- Xamarin Android
- Xamarin iOS
- Xamarin Forms
What’s new?
There are three major changes in this version: Xamarin Support, NavigationService and DialogService, and Portable Class Library support.
Xamarin support
This is the big news that I announced and demoed at Evolve. The new MVVM Light contains the following improvements for Xamarin
- Binding framework for Xamarin Android and Xamarin iOS
- Commanding framework for Xamarin Android and Xamarin iOS
- ObservableAdapter for Xamarin Android
- ObservableController for Xamarin iOS
Expect a lot more information about these additions in future blog posts. While you are waiting, you can download and try my Xamarin Evolve code sample (zip file). You can also browse the source code (Codeplex / Samples / Flowers).
Of course MVVM Light also works out of the box with with Xamarin Forms as shown in the sample application above.
NavigationService and DialogService
In V5, I decided to include two classes that I had been using in most of my applications. It is a cross-platform INavigationService and IDialogService interfaces with corresponding implementations on supported platforms.
The INavigationService provides a cross-platform navigation mechanism (including passing a parameter to the target page). It supports a CurrentPageKey property as well the the NavigateTo (with or without parameter) and GoBack methods.
I will provide more information about these two interfaces and their respective implementation in future blog posts. In the meantime, you can use my Xamarin Evolve code sample (zip file) to see how these classes are used in Xamarin Android, Xamarin iOS and Windows Phone (Silverlight) 8.1.
In V5, you get an implementation of these two classes on the following platforms:
- Xamarin Android
- Xamarin iOS
- Windows 8 and 8.1
- Windows Phone (RT) 8.1
- Windows Phone (Silverlight) 8.0
- Windows Phone (Silverlight) 8.1
In other platforms, the INavigationService and IDialogService interfaces are also available, but I didn’t provide an implementation. Notably in Windows Presentation Foundation, there is not standard navigation mechanism. For this reason, even though you can of course implement your own INavigationService, I am not providing a standard class for that.
Portable class library implementation
For a long time, there were three different Nuget packages for MVVM Light: The most popular one is the “MVVM Light Libs Only” package. There is also an “MVVM Light” package and an “MVVM Light Libraries Only (PCL)” package.
In V5 however, both the “Libs Only” packages are one and the same. I am keeping the (PCL) one around a little longer to allow people to upgrade smoothly, but it is the same package all over.
For people who were using the “non-PCL” package before, this means a few changes. Most importantly, there is now a new DLL added in some places, called GalaSoft.MvvmLight.Platform.DLL. This new DLL contains some platform specific code, notably the DispatcherHelper, NavigationService and DialogService classes.
Some non-PCL remains
For technical reason, I cannot provide a PCL version for all supported frameworks, because some are mutually exclusive. The following table shows in detail how the packages are built:
Framework | Assemblies | PCL or not? |
WPF 3.5 | GalaSoft.MvvmLight GalaSoft.MvvmLight.Extras Microsoft.Practices.ServiceLocation System.Windows.Interactivity |
No |
WPF4 | GalaSoft.MvvmLight GalaSoft.MvvmLight.Extras Microsoft.Practices.ServiceLocation System.Windows.Interactivity |
No |
WPF4.5 (and 4.5.1) | GalaSoft.MvvmLight GalaSoft.MvvmLight.Extras GalaSoft.MvvmLight.Platform Microsoft.Practices.ServiceLocation System.Windows.Interactivity |
Yes |
Silverlight 4 (see note 3) |
GalaSoft.MvvmLight GalaSoft.MvvmLight.Extras Microsoft.Practices.ServiceLocation System.Windows.Interactivity |
No |
Silverlight 5 (see note 3) |
GalaSoft.MvvmLight GalaSoft.MvvmLight.Extras Microsoft.Practices.ServiceLocation System.Windows.Interactivity |
No |
Windows Phone 7.1 (see note 3) |
GalaSoft.MvvmLight GalaSoft.MvvmLight.Extras Microsoft.Practices.ServiceLocation System.Windows.Interactivity |
No |
Windows Phone (Silverlight) 8 | GalaSoft.MvvmLight GalaSoft.MvvmLight.Extras GalaSoft.MvvmLight.Platform Microsoft.Practices.ServiceLocation System.Windows.Interactivity |
Yes |
Windows Phone (Silverlight) 8.1 | GalaSoft.MvvmLight GalaSoft.MvvmLight.Extras GalaSoft.MvvmLight.Platform Microsoft.Practices.ServiceLocation System.Windows.Interactivity |
Yes |
Windows Phone (RT) 8.1 (see note 1) |
GalaSoft.MvvmLight GalaSoft.MvvmLight.Extras GalaSoft.MvvmLight.Platform Microsoft.Practices.ServiceLocation |
Yes |
Windows Store (RT) 8 and 8.1 | GalaSoft.MvvmLight GalaSoft.MvvmLight.Extras GalaSoft.MvvmLight.Platform Microsoft.Practices.ServiceLocation |
Yes |
Xamarin Android | GalaSoft.MvvmLight GalaSoft.MvvmLight.Extras GalaSoft.MvvmLight.Platform Microsoft.Practices.ServiceLocation |
Yes |
Xamarin iOS | GalaSoft.MvvmLight GalaSoft.MvvmLight.Extras GalaSoft.MvvmLight.Platform Microsoft.Practices.ServiceLocation |
Yes |
PCL (for class libraries) (see note 2) |
GalaSoft.MvvmLight GalaSoft.MvvmLight.Extras Microsoft.Practices.ServiceLocation |
Yes |
NOTES
Microsoft.Practices.ServiceLocation is added through a reference to the CommonServiceLocator Nuget package by Microsoft Patterns and Practices.
For the PCL versions, the GalaSoft.MvvmLight and GalaSoft.MvvmLight.Extras assemblies are the same binary file.
Note 1: This version doesn’t include EventToCommand, please use InvokeCommandAction instead.
Note 2: This version is what you get when you add MVVM Light to a Xamarin Forms application. This package is also used when you add MVVM Light support to a satellite portable class library used in your application.
Note 3: Legacy support; some new features might not be available.
Installation
As of now, you can install MVVM Light V5 in your applications.
With Nuget:
- MVVM Light Libraries Only
- MVVM Light (with ViewModelLocator and MainViewModel)
If you are upgrading an existing application, I recommend removing the old Nuget package first and then re-adding the new Nuget package. You will probably have to update a few references and “using” directives but it shouldn’t be too painful.
Visual Studio Extension (includes Code snippets and Templates)
Available at this address (Visual Studio 2012 | Visual Studio 2013), or through the “Tools / Extensions and Updates” menu. I recommend uninstalling the old MVVM Light package first, and then installing the new one.
I hope that these improvements will help you build amazing applications! Of course, I always welcome your feedback.
Happy coding
Laurent