MEFedMVVMDemo and binding to SelectedUser.Name ?

Sep 26, 2010 at 10:14 AM
Edited Sep 26, 2010 at 10:48 AM

Hello Marlon,

I found your framework right in time. At the moment I am studying your samples. Then I stumbled across this line of code: 


// View
<TextBlock Text="{Binding SelectedUser.Name}" />

// ViewModel
public User SelectedUser
            get { return _selectedUser; }
                _selectedUser = value;
                OnPropertyChanged(() => SelectedUser);

I have read Josh Smith MVVM MSDN Magazine article very often (although I do not like this workspace stuff...) But I can not remember having ever read in his article to bind directly to the property of a MODEL.

Josh Smith always has delegated the Name Property to the User.Name.

Do I misunderstand anything wrong with MVVM? Or do you prefer a more practical style?

By the way, I would find the name MEFeedMVVM even cooler ;-)


Sep 26, 2010 at 1:27 PM

The view model is a facilitator of the View. If the View needs the name of a User and the User object has it, its ok to bind directly to it.


The way you should think about it is what would you achieve more by adding a property UserName in the ViewModel that just delegates to User.Name instead of simple binding directly to the property you need. 

Sep 26, 2010 at 6:02 PM

quote:"...what would you achieve more by adding a property UserName in the ViewModel ..."


I would get nothing more, right. I just wondered as you are in the wpf disciples club ;-) that you take the mvvm pattern strictly. I am just having a problem, that your View knows now the Model.

And yes being productive is more important that sticking 100% to patterns...

Sep 28, 2010 at 8:47 AM

MVVM does not say that a view should never bind to a property in a Model! MVVM says the ViewModel is a facilitator of the View. If there is no need for any facilitation then go ahead and bind to what you want. On the other hand if you want to cluter your code by having a property in the ViewModel for everything you need to bind to, go ahead but I really do not see that as being good. 

Sep 30, 2010 at 5:05 PM

quote:"MVVM does not say that a view should never bind to a property in a Model!"

You are really shocking me now. Actually I came not here to talk about who is right and not etc... so I will put that disput down and accept its a pattern I can follow it 100% or only 50%.

Have you ever read Josh Smith article about MVVM -actually I do not dare to ask this ;-) - , yes Karl Shifflets MVVM architecture diagramm that we all know does not wrap a Model into a ViewModel. I think its just so damn hard using MVVM because too many opinions make the pattern looking crippled/unusable and I lose the motivation using it.

Btw. a real question now Marlon. Does your MEFMVVM thingie support View AND ViewModel first approach?

Oct 2, 2010 at 10:38 AM

Yes it does.. When you export the view model you can pass true as parameter which will tell MEFedMVVM that at runtime it should not inject the ViewModel to the View but only satisfy its imports

[ExportViewModel("myvm", true)]