In this demonstration, we will see how can we separate the business logic (ViewModel) from the WPF Application and put it in separate class library project and use it.
The idea behind the separation of ViewModel is reuse ability of ViewModel for many other XAML base projects.
Note
Read previous article Getting started with MVVM Light with WPF before reading this one.
Step 1
We will add the new class library project inside the Business logic layer.


Step 2
Add the “MVVMLightLibs” package from NuGet. This package contains the set of components, which are required for ViewModel implementation in class library project.
“MVVMLightLibs” package is distinguished from the MVVMLight. MVVMLight contains all library & components but MVVMLightLibs contains subset of those components.


After successful installation, remove the “Class1.cs” file from the project.
Step 3
Copy ViewModel folder from WPFDemo Application to BusinessLogic class library project.

Modify all the namespaces in MainViewModel.cs and ViewModelLocator.cs, since these files are now a part of ClassLibrary project.
- namespace WPFDemo.BusinessLogic
- {
- /// <summary>
- /// This class contains static references to all the view models in the
- /// application and provides an entry point for the bindings.
- /// </summary>
- public class ViewModelLocator
- {
- .
- .
- .






Join the conversation! Your thoughts help the community grow.