Incoerent behaviour in ViewModelBase.RaisePropertyChanged<T>(Expression...) overload

Jul 28, 2012 at 7:22 PM

In ViewModelBase, in the method body with signature:

protected virtual void RaisePropertyChanged<T>(Expression<Func<T>> propertyExpression, T oldValue, T newValue, bool broadcast)

you don't call into base RaisePropertyChanged method, like in other methods of the class, but you call the PropertyChangedHandler directly...

Is there a reason for doing so? Maybe I'm too tired, but I think it could be refactored like the other overload of the method..

Hope this helps (not so much I know, but a cleaner code is a better code don't you think? ;)

Cheers
Paolo

Coordinator
Jul 31, 2012 at 3:14 PM

I have this on my backlog though with a rather low priority to be honest. I need to check it out in details first. I remember that back then I tried to consolidate that code but for some reason it didn't quite work so I left it. I will check it out again.

Cheers,
Laurent

Sep 19, 2012 at 9:13 PM

First of all, just want to say thanks for MVVM Light, its a great tool.

Thought I'd throw in my thoughts here as I ran in to an issue related to this today.  I wanted to override RaisedPropertyChanged and run some special logic there.  I got to digging around and seen that there were 4 overloads, two in ViewModelBase and two in ObservableObject.

protected virtual void RaisePropertyChanged<T>(Expression<Func<T>> propertyExpression, T oldValue, T newValue, bool broadcast)
protected virtual void RaisePropertyChanged<T>(string propertyName, T oldValue, T newValue, bool broadcast)
protected virtual void RaisePropertyChanged<T>(Expression<Func<T>> propertyExpression)
protected virtual void RaisePropertyChanged(string propertyName)

Ideally it would be nice to override "RaisedPropertyChanged(string propertyName)" in ObservableObject and have all others call up to it.  Maybe I'd have to override that and the Expression<Func<T>> versions as well.  As it currently stands though, I have to rely on the specifics of what is going on under the hood and override both ObservableObject methods as well as "protected virtual void RaisePropertyChanged<T>(Expression<Func<T>> propertyExpression, T oldValue, T newValue, bool broadcast)" on ViewModelBase but NOT "protected virtual void RaisePropertyChanged<T>(string propertyName, T oldValue, T newValue, bool broadcast)", otherwise, my logic could run twice.  Not a huge deal, but it just leaves my code heavily reliant on how things are currently set up and easily breakable with any potential new versions of MVVM Light.