I found two ways to use M-V-VM pattern in WPF:
- allocate the ViewModel into the View’s code behind (setting it as the DataContext);
- allocate the ViewModel into a XAML file and create the corresponding view using a DataTemplate.
The Model can be allocated into the ViewModel’s constructor.
What do you think about this way of using M-V-VM pattern? What are best practices relative to it?
Thank you
I tend to follow #2 and have found it to be the most flexible. As a best practice I would move these
DataTemplate‘s intoResourceDictionary‘s so they can be shared amongst XAML that will require them.