2016-11-22 59 views
0

我的Xaml中有一個列表視圖,它綁定到我的數據模型中的ActiveList屬性。列表視圖在更改集合時未刷新

根據選擇什麼,我想將列表的內容更改爲另一個列表。如果我通過視圖模型進行調試,我可以看到列表正在被分配新列表,但這並未反映在UI中!

這些列表是實現INotifyCollectionChanged接口的ObservableCollections。那麼爲什麼不刷新UI?

視圖模型:

public TcgType SelectedTcgType 
     { 
      get { return _selectedTcgType; } 
      set 
      { 
       Set(ref _selectedTcgType, value); 
       switch (value.Name) 
       { 
        case "Yugioh": 
         ActiveCards = YugiohCards; 
         break; 

        case "Hearthstone": 
         ActiveCards = HearthStoneCards; 
         break; 
        case "DBZ": 
         ActiveCards = DbzCards; 
         break; 
        case "Pokemon": 
         ActiveCards = PokemonCards; 
         break; 

       } 

       //Set(ref _selectedTcgType, value); 
      } 
     } 

設定功能:基於我Set方法

public bool Set<T>(ref T field, T value, 
      [CallerMemberName] string propertyName = null) 
     { 
      if (EqualityComparer<T>.Default.Equals(field, value)) 
       return false; 

      field = value; 
      RaisepropertyChanged(propertyName); 
      return true; 
     } 
+0

也許你需要[ObservableCollectionEx(http://stackoverflow.com/questions/269073/observablecollection-that-also-monitors-changes-on-the-elements-in-collection) –

回答

0

中,我並沒有提高物業的事件改變了收集。僅適用於listview中的選定值。

我在switch語句中添加了一個RaisePropertyChanged("ActiveList")並更新了它。

protected void RaisepropertyChanged(string propertyName) 
     { 
      PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 
     }