by Laurent Bugnion via Silverlight on 5/7/2011 8:18:31 PM
There was already a version of MVVM Light on Nuget before. However the old version did not support Windows Phone 7. This is now corrected. Also the new version now adds a ViewModelLocator to your project and includes it in App.xaml.
NuGet is a mechanism allowing to add packages (assemblies, source code…) to an existing project. All versions of MVVM Light are supported (WPF3.5, WPF4, Silverlight 3, Silverlight 4, Windows Phone 7).
In order to install NuGet and learn more about this cool package manager, go to http://nuget.org
To find MVVM Light in NuGet, follow the steps:
Note: Should that menu item be missing, you need to install the NuGet package manager. Go to http://nuget.org and follow the indications.
After these steps, the following changes have been made to your project:
With the new file structure, the ViewModelLocator is exposed in App.xaml (global resources) and can be used as the source of the DataContext bindings.
The MainViewModel that has also been added to the project is exposed in the ViewModelLocator as a property. for more details about this architecture, please refer to Understanding the MVVM pattern and Deep Dive MVVM.
Note: In case you do not need the MainViewModel in your project, feel free to remove this class.
In order to use the MainViewModel as the DataContext of the MainPage or MainWindow, use the following steps:
DataContext="{Binding Main, Source={StaticResource Locator}}"
From now on, the DataContext of the MainPage/MainWindow is set to the instance of MainViewModel exposed by the ViewModelLocator. These steps can be repeated at will with different views/viewmodels pairs.
The DataContext can also be databound visually in Expression Blend with the following steps.
Some users prefer to work without a ViewModelLocator, and are only interested in the MVVM Light assemblies. Unfortunately there is not really a way to specify options when using NuGet. So I created a different “barebone” package, named “MvvmLightLibs” which contains only the libraries and nothing else. To install this “barebone” version, follow the steps above, but select “MvvmLightLibs” instead of MvvmLight.
There is also a way to use NuGet without Visual Studio, from the command line. A good description is available on this blog.
I am very interested to know what you guys think of the experience with NuGet. Please let me know if you like it!
Original Post: MVVM Light V3 on NuGet (now with WP7 support)
The content of the postings is owned by the respective author. Silverlight Feeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on Silverlight Feeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.