DependencyObject issue

Mar 18, 2012 at 9:51 PM

I have started using MVVM Light Toolkit  this month and I love it from the first seconds but there is one small thing that I don't understand. Maybe some one can help me.

In MVVM Light Toolkit there are several usefull snippets - two of those are: mvvmpropa & mvvmpropdp
But.... it seems that ViewModelBase is not inherit from DependencyObject class and therefore in fact we are unable to use those two snippets and generaly we can't use DependencyProperties if we choose ViewModelBase as our base class.

Am I correct?
Is there any reason why ViewModelBase doesn't inherit from DependencyObject?
Are you have plans to prepare something like DependencyViewModelBase?

Thanks in advance
jpyt

Coordinator
Mar 19, 2012 at 10:01 AM

Hi,

DependencyObjects are also observable but they are applied to UI elements rather than simpler data objects. They are heavier and use the DependencyProperty (DP) system for notifications. DPs are not just for observability but they have additional features that are useful when building UI.

For data objects, we prefer the lighter weight INotifyPropertyChanged implementation (as in ObservableObject, or ViewModelBase).

The two snippets you mention are useful when creating dependency properties, for example when doing UI code or creating custom controls. They are not strictly MVVM, true, but they are so useful that I included them anyway. There are no plans to create a “DependencyViewModelBase”

Hope that helps,

Laurent

From: jpyt [email removed]
Sent: Sunday, March 18, 2012 9:52 PM
To: laurent@galasoft.ch
Subject: DependencyObject issue [mvvmlight:349115]

From: jpyt

I have started using MVVM Light Toolkit this month and I love it from the first seconds but there is one small thing that I don't understand. Maybe some one can help me.

In MVVM Light Toolkit there are several usefull snippets - two of those are: mvvmpropa & mvvmpropdp
But.... it seems that ViewModelBase is not inherit from DependencyObject class and therefore in fact we are unable to use those two snippets and generaly we can't use DependencyProperties if we choose ViewModelBase as our base class.

Am I correct?
Is there any reason why ViewModelBase doesn't inherit from DependencyObject?
Are you have plans to prepare something like DependencyViewModelBase?

Thanks in advance
jpyt

Mar 19, 2012 at 1:29 PM

Hi Laurent,

Thank you for quick reply.
OK - Now I understand the purpose for those snippets.

PS. Really great work with MVVM Light Toolkit - It is so simply, so light but so usefull! I appreciate. You have a big beer with me.

Coordinator
Mar 19, 2012 at 1:40 PM
I will look forward to that :-)

Cheers,
Laurent

Sent from my Windows Phone

From: jpyt
Sent: 19.03.2012 13:30
To: laurent@galasoft.ch
Subject: Re: DependencyObject issue [mvvmlight:349115]

From: jpyt

Hi Laurent,

Thank you for quick reply.
OK - Now I understand the purpose for those snippets.

PS. Really great work with MVVM Light Toolkit - It is so simply, so light but so usefull! I appreciate. You have a big beer with me.

May 1, 2012 at 12:07 PM

Hi

Just to clarify, if I have a View that has a ListBox for example that has a binding to an ObservableCollection on a ViewModel.  If that collection is a collection of objects from one of my Model classes and I want the View to update if I change the value of one of the properties on the Model object then do you recommend DependencyObject or INotifyProperty on the Model object?  Is your choice driven by cross threading implications?  Or am I going against how you intend this to work completely?!

Thanks

Coordinator
May 21, 2012 at 7:54 AM

Hi,

Sorry for the delay.

The choice to work with INPC on the Model is driven by simplicity. Using a DO there is overkill because DOs are quite heavy and "drag" with them a lot of features that only make sense on a UI. For instance, DOs are not serializable while INPC implementations are, of course.

In MVVM Light V4, you can use the ObservableObject class and derive from this.

Cheers,

Laurent