views:

360

answers:

2

I got a scenario like this

Class Parent 
{
    Property  A;
 }

 Class A 
 {
      Property X
 }

How can I get PropertyChangedNotification on Property A when X changes? I don’t want to refer ‘Parent’ in class A or any kind of event which spoils my decoupling. What I basically want is to make the Parent.IsDirty=true. This is avery simplified version of my story, I got tens of classes like Parent, so I am looking for some generic way to handle this.

Please note that this is not the actual code :) I got all INotifyPropertyChanged implementation. I am just wondering any easy mechanism like RaisePropertyChanged("A.X")

+2  A: 

You can try to register the propertychanged event in the parent class. In the constructor you can subribe to the event:

public Parent()
{
    A.OnPropertyChanged += OnAPropertyChanged;
}

void OnAPropertyChanged(object sender, PropertyChangedEventArgs e)
{
    if (e.PropertyName == "X")
        if(PropertyChanged != null)
             PropertyChanged(this, new PropertyChangedEventArgs("A"))
}

hope this helps...

Roel
A: 

Do something like this:

 Class Parent  
 { 
    Property A; 
 } 

 Class A  
 { 
    private Property _X;
    public Property X { get{return _X;} set{_X=value;/*insert event to tell PArent here*/}}
 } 
Tommy
that is my question too. How to tell to the parent is the issue.
Jobi Joy
Well does the child have a reference to the parent?
Tommy