I have got a collection of viewModels(InputViewModel) in an other viewModel(ScenarioManager). each InputviewModel has an instance of a Class(RestOfInput) which contains properties able to raise the OnPropertyChanged. when one of these properties changes the event is handled by this method (in InputViewModel) :
public void TestAfterChanges(object sender, PropertyChangedEventArgs e)
{
MessageBox.Show("not ref");
bool isInTheList = false;
RestOfInput roi = sender as RestOfInput;
string prop = e.PropertyName;
if (prop!="NameFile")
{
Difference d = new Difference();
d.Length = prop;
d.Value1 = reference.RoI.getValueByPropertyName(prop);
d.Value2 = roi.getValueByPropertyName(prop);
foreach (Difference diff in _ListOfDifferences)
{
if (diff.Length==prop)
{
if ( (Math.Abs(d.Value2-d.Value1)>0.001*d.Value1))
{
//replace by le new one
_ListOfDifferences.Insert(_ListOfDifferences.IndexOf(diff), d);
_ListOfDifferences.Remove(diff);
}
else
{
//if change make the field value equal to the ref then remove from difference list
_ListOfDifferences.Remove(diff);
}
isInTheList = true;
}
}
if ((Math.Abs(d.Value2 - d.Value1) > 0.001 * d.Value1) && isInTheList==false)
{
_ListOfDifferences.Add(d);
}
}
}
这种方法只是概述了这一具体案件与参考案件之间的差别。
Now if the reference case changes I have to update all the cases and the event is handled in ScenarioManager :
public void refCaseChanging(object sender, PropertyChangedEventArgs e)
{
MessageBox.Show("ref");
string propname = e.PropertyName;
foreach (InputViewModel item in _casesList)
{
if (item!=inpVM)
{
item.RoI.OnPropertyChanged(propname);
}
}
}
笔录是参考案例。
Then I have this behavior : -if I change a field in a case which is not the reference case : everything is ok. -if I change a particular field in the reference case : the first time, everything is ok. But the second time, only the reference case and the first case (in the collection) which is not the reference case are updated> It is like the foreach loop is broken..
任何复制品。
如果信息不明确,请告诉我(不易解释;)