2010-10-06 144 views
0

我在其他viewModel(ScenarioManager)中獲得了viewModels(InputViewModel)的集合。 每個InputviewModel都有一個Class(RestOfInput)實例,該實例包含能夠引發OnPropertyChanged的屬性。 當這些屬性中的一個改變該事件由該方法(在InputViewModel)處理:OnPropertyChanged反應第一次和第二次不同

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

      } 


     } 

此方法給出只是一個該特定情況和基準情況之間的差異彙總。

現在,如果引用情況的變化我要更新所有的案件和事件在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是參考案例。

然後,我有這樣的行爲: - 如果我改變了一個案件,而不是參考案例的領域:一切都很好。 - 如果我改變參考案例中的特定領域:第一次,一切都很好。 但是第二次,只有參考案例和非參考案例中的第一個案例(在集合中)更新> 這就像foreach循環被打破。

任何解釋。

如果消息是不明確的,請告訴我(不容易解釋;))

回答

1

例外可以說明,處理停止(雖然人們期望它會被捕捉並顯示somewehre)。

你有沒有試圖讓VS停止你的程序時,拋出異常? (如果你以前從未這樣做過,請轉到調試/例外,並選中CLR例外的複選框)

+0

我認爲Timores正在爲此付出代價。我可以在item.RoI處看到一個可能的空引用異常(不要假設if(item!= inpVM)意味着item不爲空)並且異常在執行樹中的某處被捕獲,而您並不知道。 +1 – 2010-10-06 06:23:49

+0

Timores感謝您的回答非常有用:問題出在第一種方法的foreach循環上。由於我修改了Collection _ListOfDifference,因此循環無法結束。 – Gerrrard 2010-10-06 06:27:51

+0

Tri Q,沒有測試只是因爲參考案例屬於集合,但這個不能被刪除。雖然永遠不會是null.Thanks你 – Gerrrard 2010-10-06 06:32:41

相關問題