Provider pattern in WPF application
In Patterns in Action 4.0 solution, there is WPF application in PL. This application implements MVVM pattern.
There are 3 projects in WPF folder.
V -> VM -> M
That means View should not interact with Model layer.
However, in this solution, there are some problems:
1) View > WindowLogin.xaml.cs file has a button and in the click event handler, an exception handling implemented. Is this correct? is it not better to handle this behavior in ViewModel layer?
2) in this button click event handler, there is direct interaction with "Model". Because Provider.cs is placed in WPF Model application which breaks MVVM pattern rule. Am I wrong?
Can Pekerler, Apr 05, 2012
You shouldn't have a click even handler in your code behind. Use a Command (maybe with a commandHelper) to handle this.
The functionality of the click event is handled in the method of the Command in the ViewModel. If you want to use a messagebox you use a viewmanager (with an interface and IoC) and use a method on the viewmanager to handle the messagebox.
You can also have a look at Caliburn micro.
Wesley Walraeve, Aug 08, 2012