Dofactory.com
Dofactory.com
 Back to list
Views:   9K
Replies:  1
Archived

Provider pattern in WPF application

Hi guys,

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.
  • WPF Application (View)
  • WPF Model
  • WPF ViewModel
As I know MVVM pattern has such a rulue.

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?

try
            {
                var provider = new Provider();
                provider.Login(username, password);

 Thanks

Can
Can Pekerler, Apr 05, 2012
Reply 1
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
Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Cookies       Do Not Sell       Licensing      
Made with    in Austin, Texas.  - vsn 44.0.0
© Data & Object Factory, LLC.