Update: Sorry I wasn't clear about the question. I should've mentioned that:
Suppose I can't change the Base, and..
There are many properties in the Base. The sample code is simplified.
Here I have an object of this (base)class that is deserialized over the network.
public class Base
{
public string Name { get; set; }
}
Now I wish to bind its properties on an WPF application so I implement INotifyPropertyChanged on a derived class.
public class Derived : Base, INotifyPropertyChanged
{
private string _derivedName;
public string DerivedName {
get { return _derivedName; }
set
{
_derivedName = value;
RaisePropertyChanged("DerivedName");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void RaisePropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
Now my question is : How do I raise the property changed event when Base.Name is changed?
I know I can remove the inheritance and re-implement every base property and raise the event, but is there any better way?