|
Hey ... stuff happens.
But it wasn't an idle question because I don't know what string to pass to the PropertyChangedEventArgs for the manager.
Anyway, the following code, which would go inside the Employee custom partial class, works for the "Employee.Manager" scenario we've discussed.
Observe that I dreamed up a string to send as the "PropertyName" when I raise PropertyChanged on the manager (which I do via the EntityAspect.ForcePropertyChanged method).
I feel strongly that this is not a wise idea. You be the judge.
---
protected override void OnPropertyChanged(System.ComponentModel.PropertyChangedEventArgs e) { if (HeardDirectReportChanged(e)) return ; base.OnPropertyChanged(e); RaiseManagerPropertyChanged(); } // Note: Don't recommend this approach at all. // PropertyChanged is not raised for every change to an employee. // PropertyChanged not raised when entity changes are rolled back // e.g., after IEditableObject.CancelEdit or RejectChanges // Manager won't hear about any of these events via this mechanism private bool HeardDirectReportChanged(PropertyChangedEventArgs e) { var propertyName = e.PropertyName; if (!propertyName.StartsWith("DirectReport '" )) return false ; // Do something var x = this.FullName + " heard from " + propertyName; return true ; // assume don't actually want to continue with PropertyChanged } private void RaiseManagerPropertyChanged() { var mgr = this.Manager; var mgrEa = Manager.EntityAspect; var selfEa = this.EntityAspect; // Reasons not to continue if (this == mgr || // if manage oneself !selfEa.IsChanged || // self unchanged selfEa.EntityState.IsDetached() || // self is detached mgrEa.IsNullEntity || // have no manager mgrEa.EntityState.IsDetached() // manager is detached ) return ; mgr.EntityAspect.ForcePropertyChanged( new PropertyChangedEventArgs ( string .Format("DirectReport '{0}: {1}'" , EmployeeID, FullName))); }
|