2016-11-22 62 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)); 
     }