Injecting (INotifyPropertyChanged functionality) to an instance of an class
Posted
by no9
on Stack Overflow
See other posts from Stack Overflow
or by no9
Published on 2010-03-18T11:15:36Z
Indexed on
2010/03/18
13:31 UTC
Read the original article
Hit count: 402
c#
|inotifypropertychanged
Hi !
I have a class that implements INotifyPropertyChanged. I create an instance of a class in some viewModel. Is it possible to remove this functionality from the class and inject it after the instance was created? I heard that ICustomTypeDescriptor would make this happen, but i dont know how to use it.
public class C : ICustomNotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public int _id;
public string _name;
public int Id
{
get { return _id; }
set
{
if (_id == value)
{
return;
}
_id = value;
OnPropertyChanged("Id");
}
}
public string Name
{
get { return _name; }
set
{
if (_name == value)
{
return;
}
_name = value;
OnPropertyChanged("Name");
}
}
public void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
© Stack Overflow or respective owner