Split my view/viewmode/model into separate visual studio projects. I am using MVVMLight toolkit version 5.3.0, visual studio 2015, C# and WPF application for desktop only
solution structure
- Project 1: UI (WPF application)
- Project 2: View (WPF user control library - to store all Views)
- Project 3: ViewModel (Class library - to store all ViewModels)
- Project 4: Model (Class library - to store all Models)
- Project 5: Common (Class library - used my Model and ViewModel - stores my - classes and interfaces only)
references
- Common: referenced by Model and ViewModel projects
- Model: referenced by ViewModel project
- ViewModel: referenced by View project
- View: I assume my UI should reference only my View project
so following MVVM my View knows about ViewModel only an my ViewModel knows about my Model.
so now my questions:
1) In which project do I put the ViewModelLocator? (right now I placed it in my View project) 2) Should my UI project reference only my View project? 3) In the MVVM light project, the "DataContext="{Binding Main, Source={StaticResource Locator}}" is in the View xaml file and the Locator defined in app.xaml. how do I bind my View to my ViewModel using ViewModelLocator?
I've checked several posts and can't figure these answers
Update:
this is what I made to get it work:
step 1: changed the references:
- UI references View and ViewModel projects
- View references ViewModel project
- ViewModel references Model and Common
- Model references Common
step 2: moved the ViewModelLocator to ViewModel project (from View)
step 3: Added back the datacontext in my View (usercontrol) as DataContext="{Binding UserDetailsVM, Source={StaticResource Locator}}"
step 4: added the to my App.xaml of the UI project
step 5: in the MainWindow of my UI project, I added my view in the xaml as
Notes: - UI project has no references to MVVMLight - Both View and ViewModel projects has reference to MVVLightLibs and CommonServicesLocator
It works, but this is correct way of doing it?