Hi,
I'm creating 2 instances of the same model for 2 windows. The class to make the communication is named 'manager'.
I want to notify the second window when a property is changed in the first window. The model implements
INotifyPropertyChanged
When the value is changed in the second, it's raising the event
public bool MyProperty
{
get { return _myProperty; }
set
{
_myProperty = value;
OnPropertyChanged();
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName]string caller = null)
{
var handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(caller));
}
}
In the manager, I'll receiving a notification and I'm updating all instances of the models
private void Vm_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
var prop = TypeDescriptor.GetProperties(sender)[e.PropertyName];
if (prop != null)
{
object val = prop.GetValue(sender);
SynchronizeViews(e.PropertyName, val);
}
}
private void SynchronizeViews(string propertyName, object val)
{
foreach(MainViewModel vm in MainViewModelList)
{
vm.MyProperty = (bool)val;
}
}
At the end, it's not working because I'm making a loop !!!!
What I have tried:
See the content of the message describing what I have tried.