As you know in WPF
applications if you want to bind some property of specific class to a control's property, you must implement INotifyPropertyChanged
interface to that class.
Now consider that we have many normal classes which didn't implement INotifyPropertyChanged
. they are very simple class as this example:
public class User : ModelBase
{
public int Id { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
// ...
}
for example I want to bind the UserName
to a TextBox
, So i should write another new User
class that implements INotifyPropertyChanged
like this:
public class User : INotifyPropertyChanged
{
public string Password { get {return _Password}}
set {_Password=value;OnPropertyChanged("Password");}
// ... Id and UserName properties are implemented like Password too.
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
// ...
}
Now my question is that is there or you know any mechanism or trick to simplify that?
consider that we have more than 100 models and maybe they be changed.
I'm thinking about a way, something like using a generic class to do it (Edited):
public class BindableClass<NormalClass> { ...adding ability to bind instructions using reflection... }
NormalClass NormalInstance = new NormalClass();
// simple class, does not implemented INotifyPropertyChanged
// so it doesn't support binding.
BindableClass<NormalClass> BindableInstance = new BindableClass<NormalClass>();
// Implemented INotifyPropertyChanged
// so it supports binding.
Of course i'm not sure that is it good approach or not! it is just an idea to clarify my question.
Please don't tell me there is no way or it's impossible! there is hundreds of models!!!
Thanks.