views:

20

answers:

1

hello, 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);
                }

            }


        }

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 ;) )

+1  A: 

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)

Timores
I think Timores is on the money. I can see a possible null reference exception at item.RoI (don't assume that passing through if(item != inpVM) means item is not null) and the exception was caught somewhere up in the execution tree that you were not aware of. +1
Tri Q
Timores thanks for the answer very useful : the problem is on the foreach loop of the first method. Since I modify the Collection _ListOfDifference the loop can not end.
Gerrrard
Tri Q, no the test is just because the reference case belongs to the collection but this one can not be removed. Though is never null.Thanks you
Gerrrard