Click here to Skip to main content
15,886,110 members
Home / Discussions / WPF
   

WPF

 
QuestionWPF Pin
Syed Shahid Hussain8-Feb-10 11:08
Syed Shahid Hussain8-Feb-10 11:08 
AnswerRe: WPF Pin
Not Active8-Feb-10 11:17
mentorNot Active8-Feb-10 11:17 
AnswerRe: WPF Pin
V.8-Feb-10 21:25
professionalV.8-Feb-10 21:25 
QuestionProblem w/ ClickOnce deployment and EventLogs Pin
vsaratkar8-Feb-10 9:46
vsaratkar8-Feb-10 9:46 
QuestionDragging outlook attached documents into a WPF app Pin
RugbyLeague8-Feb-10 3:59
RugbyLeague8-Feb-10 3:59 
AnswerRe: Dragging outlook attached documents into a WPF app Pin
Pete O'Hanlon8-Feb-10 4:24
mvePete O'Hanlon8-Feb-10 4:24 
GeneralRe: Dragging outlook attached documents into a WPF app Pin
RugbyLeague8-Feb-10 5:34
RugbyLeague8-Feb-10 5:34 
QuestionMVVM standardization [modified] Pin
Michael Sync7-Feb-10 5:46
Michael Sync7-Feb-10 5:46 
Hello,

Someone in Silverlight posted[^] that MVVM currently lacks standardization so that everyone has own favor..

That's why Me and a few guys from WPF Disciples are actively discussing about MVVM that everyone agreed. I totally understand that we have implemented the pattern in different ways and we mixed the several patterns or create our own pattern based on our project's need or to make the developers' life easier.. But forget about those difficulties or the special need of your project. Let's discuss about the standard rules of MVVM pattern that everyone agreed. I posted some of my thoughts here[^] as well.

Why MVVM?

- Testabiltiy ( ViewModel is easier to unit test than code-behind or event driven code)
- Clear seperation between UX designer and developer
- Increases the “Blendability” of your view
- Model never needs to be changed to support changes to the view
- ViewModel rarely needs to be changed to support changes to the view
- No duplicated code to update views

Do and Don’t in View

- shouldn’t contain any logic that you want to test : As Glenn said that MVVM is not code counting exercise, we can write code in code-behind. But you should never write any logic that you want to test. For example: If user select a country then you want to display the list of states or city in your view. This is the business requirement so you should have unit test to test this logic. So, you shouldn’t write it in code-behind.
- can be a control or Data Template
- Keep the view as simple as possible. : We can still use Data Trigger or Value Converter or Visual State or Blend Behivor in XAML with care.
- use attached property if something is not bindable :

Do and Don’t in ViewModel

- Connector between View and Model
- Keep View State, Value Conversion (You can create the data structure that you want to display in ViewModel instead of using ValueConverter. For example: You need to show the Name instead of First Name and Last name. Your Model can have First Name and Last Name but You can create Name property in ViewModel. )
- No strong or weak (via Interface) reference of View
- Make VM as testable as possible (e.g. no call to Singleton class)
- No Control related Stuff in VM ( Because if you are changing the view then you will have to change VM as well. )

Model

- can be Data Model, DTO, POCO, auto-generated proxy of domain class and UI Model based on how you want to have the separation between Domain Service and Presentation Layer
- No reference to ViewModel

Do you have any suggestion or comment for that?

We have one disagreement in our group. Some said that it's okay to have the interface of View in ViewModel. But some said that if View Model has the interface of View then it will be MVP pattern.

One of our MVVM experts say about MVVM Vs MVP

**View => ViewModel**

- MVVM the view is directly bound to the ViewModel and talks to the VM through databinding
- In MVP, the view is bound to a model hanging off the SupervisingController or not bound at all (passive view).

**ViewModel => View**

MVVM

1. INPC / Property binding
2. Events
3. Messages (Event Aggregator/Messenger/RX framework)
4. Through an intermediary such as a service
5. Through an interface
6. Through delegates (View passes delegates to the VM which it can use to call it back. For example VM might expose a SetActions method which the View calls passing it delegates.

MVP

1. With Passive View the properties are not using databinding, instead the view property getters and setters are used to directly set the control value.
2. Events
3. Messages (Event Aggregator/Messenger/RX framework)
4. Through an intermediary such as a service
5. Through an interface
6. Through delegates (View passes delegates to the VM which it can use to call it back. For example VM might expose a SetActions method which the View calls passing it delegates.

MVP Vs MVVM

All are the same except the following.

1. View talks to ViewModel via binding. In MVP, View directly calls the Presenter.
2. ViewModel has INPC / Property binding while Presenter doesn't have. Presenter set the value to the property of control directly.

The rest are the same.

What do you think about that idea?

Do you think that it's okay for ViewModel have the interface of View?

If you like to add more then you are welcome to add... Smile | :)

The whole idea about this post is to get the same understanding of MVVM pattern in Community. Feel free to let me know if you have any comment or doubt. Thanks.
modified on Sunday, February 7, 2010 10:10 PM

AnswerRe: MVVM standardization Pin
Wes Aday8-Feb-10 12:35
professionalWes Aday8-Feb-10 12:35 
QuestionDataTemplate with List binding Pin
pbalaga6-Feb-10 9:20
pbalaga6-Feb-10 9:20 
AnswerRe: DataTemplate with List binding Pin
Pete O'Hanlon6-Feb-10 9:58
mvePete O'Hanlon6-Feb-10 9:58 
GeneralRe: DataTemplate with List binding Pin
pbalaga6-Feb-10 21:35
pbalaga6-Feb-10 21:35 
GeneralRe: DataTemplate with List binding Pin
Pete O'Hanlon6-Feb-10 22:01
mvePete O'Hanlon6-Feb-10 22:01 
AnswerRe: DataTemplate with List binding Pin
Abhinav S6-Feb-10 10:06
Abhinav S6-Feb-10 10:06 
GeneralRe: DataTemplate with List binding Pin
pbalaga6-Feb-10 21:37
pbalaga6-Feb-10 21:37 
GeneralRe: DataTemplate with List binding [modified] Pin
Abhinav S6-Feb-10 21:45
Abhinav S6-Feb-10 21:45 
GeneralRe: DataTemplate with List binding Pin
Pete O'Hanlon6-Feb-10 23:46
mvePete O'Hanlon6-Feb-10 23:46 
QuestionQuick Question About Application Launch Pin
BlitzPackage6-Feb-10 2:48
BlitzPackage6-Feb-10 2:48 
QuestionHow to get Event for the Windows.shapes.path Pin
Joe Rozario5-Feb-10 17:14
Joe Rozario5-Feb-10 17:14 
QuestionReporting with silverlight Pin
jonatan_5565-Feb-10 3:43
jonatan_5565-Feb-10 3:43 
AnswerRe: Reporting with silverlight Pin
Pete O'Hanlon5-Feb-10 11:11
mvePete O'Hanlon5-Feb-10 11:11 
GeneralRe: Reporting with silverlight Pin
jonatan_55611-Feb-10 1:46
jonatan_55611-Feb-10 1:46 
AnswerMessage Removed Pin
8-Feb-10 23:10
Perpetuum Software8-Feb-10 23:10 
GeneralRe: Reporting with silverlight Pin
jonatan_55611-Feb-10 1:50
jonatan_55611-Feb-10 1:50 
QuestionHow to show tooltip over a TreeViewItem if it is not fully Visible? Pin
Venkatesh Mookkan4-Feb-10 16:32
Venkatesh Mookkan4-Feb-10 16:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.