OnPropertyChanged reaction different the first time and the second time
I have got a collection of viewModels(InputViewModel) in an other viewModel(ScenarioManager). each Inpu开发者_Python百科tviewModel 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);
}
}
}
this method gives just a summary of the differences between this particular case and the reference case.
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);
}
}
}
inpVM is the reference case.
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..
Any explications.
If the message is not clear please tell me ( not easy to explain ;) )
An exception could explain that processing stops (although one expects that it would be caught and displayed somewehre).
Have you tried to ask VS to halt your program when an exception is thrown ? (if you have never done this before, go to Debug / Exceptions and check the check box for CLR exceptions)
精彩评论