English 中文(简体)
采购 改变的反应第一次和第二次不同
原标题:OnPropertyChanged reaction different the first time and the second time
  • 时间:2010-10-06 04:12:57
  •  标签:
  • wpf

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..

任何复制品。

如果信息不明确,请告诉我(不易解释;)

最佳回答

一种例外情况可以解释,处理站(尽管人们期望它会被抓获并展示出一些威力)。

你们是否试图在出现例外情况时要求联邦调查局停止执行? (如果你以前从未这样做,去除/例外,检查CLR例外情况的检查箱)

问题回答

暂无回答




相关问题
WPF convert 2d mouse click into 3d space

I have several geometry meshes in my Viewport3D, these have bounds of (w:1800, h:500, d:25). When a user clicks in the middle of the mesh, I want the Point3D of (900, 500, 25)... How can I achieve ...

Editing a xaml icons or images

Is it possible to edit a xaml icons or images in the expression design or using other tools? Is it possible to import a xaml images (that e.g you have exported) in the expression designer for editing?...

WPF: writing smoke tests using ViewModels

I am considering to write smoke tests for our WPF application. The question that I am faced is: should we use UI automation( or some other technology that creates a UI script), or is it good enough to ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

How do WPF Markup Extensions raise compile errors?

Certain markup extensions raise compile errors. For example StaticExtension (x:Static) raises a compile error if the referenced class cannot be found. Anyone know the mechanism for this? Is it baked ...

WPF design-time context menu

I am trying to create a custom wpf control, I m wondering how I can add some design-time features. I ve googled and can t seem to get to my goal. So here s my simple question, how can I add an entry ...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签