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;
}
也许你需要[ObservableCollectionEx(http://stackoverflow.com/questions/269073/observablecollection-that-also-monitors-changes-on-the-elements-in-collection) –