INotifyPropertyChanged Support?

Aug 5, 2011 at 4:44 AM

Does PropertyEditor support INotifyPropertyChanged or an alternative method of updating properties who's value changes from the input of another? I've looked around and am not seeing it.


Consider the case where an object has the properties Left, Right, and Width. Changing any one property would invalidate the state of the others in the PropertyEditor.




Aug 5, 2011 at 9:19 AM

hi Eric,

yes, it supports INotifyPropertyChanged - you can use code like this:


    public class LeftRightWidth : Observable
        private int left;
        public int Left
            get { return left; }
            set { left = value; RaisePropertyChanged("Left"); RaisePropertyChanged("Width"); }

        private int right;
        public int Right
            get { return right; }
            set { right = value; RaisePropertyChanged("Right"); RaisePropertyChanged("Width"); }

        public int Width
            get { return right-left; }
            set { right = left + value; RaisePropertyChanged("Right"); RaisePropertyChanged("Width"); }


where the Observable class implements INotifyPropertyChanged.

Aug 5, 2011 at 6:48 PM

Hi, Objo. Thanks for the reply. In a MVVM design this seems to get complicated. The Model View calls RaisePropertyChanged per property Set method not only for itself but for other properties who's values have changed. This requires underlying knowledge of the Model and assumptions that their values have changed even though they might not have. Also there may be many co-dependent values and the management is greatly complicated by this. In a simple Model only design each property could call RaisePropertyChanged once for itself, but then of course the advantages of a MVVM design are lost. There must be a better way to approach this.



Aug 5, 2011 at 10:51 PM

As an added thought; I would just put PropertyEditor.UpdateContent() in the PropertyEditor.PropertyChanged event to refresh the property values each change but that resets the scroll and focus.

Aug 6, 2011 at 11:46 AM

hi Eric,

the PropertyViewModel subscribes to the PropertyDescriptor's ValueChanged event (see the PropertyViewModel.SubscribeValueChanged method). When the value of your property has been changed, the PropertyViewModel will raise a INotifyPropertyChanged.PropertyChanged event and the WPF binding will be updated.

Can you post the code for your 'LeftRightWidth' viewmodel that you want to edit in the PropertyEditor?

I don't think doing a full update of the control's content is a good solution, we should only depend on notification events and WPF's binding mechanism.