internal class Model:INotifyPropertyChanged
{
public Model()
{
}
string _FirstName = "Shahir";
public string FirstName
{
get { return _FirstName; }
set
{
_FirstName = value;
OnPropertyChanged();
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged([CallerMemberName] string propertyName = "")
{
if(PropertyChanged!=null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
internal class MyViewModel:INotifyPropertyChanged
{
private Model myModel;
public MyViewModel(Model model)
{
this.myModel = model;
myModel.PropertyChanged += myModel_PropertyChanged;
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged([CallerMemberName] string propertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
string _FirstName;
public string MyFirstName
{
get { return myModel.FirstName; }
set
{
_FirstName = value;
OnPropertyChanged();
}
}
private void myModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "FirstName")
{
MyFirstName = myModel.FirstName;
}
}
}
REFERECE - https://www.codeproject.com/Questions/1055820/How-the-Model-changes-could-be-notified-to-ViewMod
0 comments :
Post a Comment