This project is read-only.

Suggestion - DependentPropertyAttribute

Nov 10, 2011 at 4:22 PM

Add a new attribute (e.g. DependentPropertyAttribute) that takes a single parameter specifying the name of a dependent property.  The RaisePropertyChanged method should be called for each dependent property specified within a DependentPropertyAttribute.

Nov 10, 2011 at 4:58 PM

How would you expect the ordering to work?  Should they be in the order or the attributes on the private field?

[DependentProperty(MyViewModel.City)]
[GenerateObservableProperty]
[DependentProperty(MyViewModel.Zip)]
[DependentProperty(MyViewModel.Country)]
private string _state;

Would translate to:

if(_state != value)
{
    _state = value;
   RaisePropertyChanged(MyViewModel.City);
   RaisePropertyChanged(MyViewModel.State);
   RaisePropertyChanged(MyViewModel.Zip);
   RaisePropertyChanged(MyViewModel.Country);
}

Nov 10, 2011 at 5:29 PM
Edited Nov 10, 2011 at 5:30 PM

I hadn't actually thought about that. However, I feel that the order should be deterministic so running them in the order as they are coded probably makes the most sense.

Nov 10, 2011 at 10:54 PM

Jeremy, Micah and I were talking and now we are thinking we should follow the RIA model by declaring OnXXXChanging and OnXXXChanged partial methods.  If a person wanted to implement the method bodies then that would be the cleanest way.  For example in the generated code:

public string State
{
  get
  {
    return _state;
  }
  set
  {
    if(_state != value)
    {
      OnStateChanging(value);
      _state = value;
      OnBeforeStateChanged();
      RaisePropertyChanged(MyViewModel.State);
      OnAfterStateChanged();
    }
  }
}

 

RIA also uses a "Validate" method which might be a good idea.  WPF has an INotifyPropertyChanging interface that supports canceling of the change.  Thoughts?