我正在使用ReactiveUI 4.1
. 我使用一个ReactiveCollection
可选项目(具有IsSelected
标志)作为另一个派生反应集合的来源,该集合使用过滤器仅查看具有IsSelected == true
. 如果在创建派生集合之前源集合预先填充了一些未/选定的项目,则视图过滤器似乎可以工作,但是当稍后源集合中的项目从选中状态变为未选中状态时,这些项目不会“消失”派生的集合。我确实在所有集合上设置ChangeTrackingEnabled
了标志true
,但它似乎没有帮助。附上我的代码片段:
private readonly ReactiveCollection<string> _sourceItems = new ReactiveCollection<string>();
private readonly ReactiveCollection<SelectableDataItem<string>> _selectableItemsView = null;
private readonly ReactiveCollection<SelectableDataItem<string>> _selectedItemsView = null;
private readonly ReactiveCollection<string> _selectedDataView = null;
///....
this._sourceItems.ChangeTrackingEnabled = true;
this._selectableItemsView =
this.SourceItems.CreateDerivedCollection<string, SelectableDataItem<string>>(i => new SelectableDataItem<string>(i) { IsSelected = true, });
this._selectableItemsView.ChangeTrackingEnabled = true;
this._selectedItemsView =
this._selectableItemsView.CreateDerivedCollection<SelectableDataItem<string>, SelectableDataItem<string>>(
i => i,
f => f.IsSelected,
(i1, i2) => 0
);
this._selectedItemsView.ChangeTrackingEnabled = true;
this._selectedDataView =
this._selectableItemsView.CreateDerivedCollection<SelectableDataItem<string>, string>(i => i.Data, f => f.IsSelected, (i1, i2) => 0);
this._selectedDataView.ChangeTrackingEnabled = true;