尝试将selectable
项ListView
从ItemsSource
binded
移至ObservableCollection
。 Debugging
表示项目已正确标记为已选中并已删除列表本身。但显示的ListView
并未更新更改,因此已删除的项目会保留shown
。
查看
<ListView BorderThickness = "0"
AlternationCount = "2"
BorderBrush = "Transparent"
ItemsSource = "{Binding TestEntries}"
Style = "{StaticResource ListViewStyle}"
ItemContainerStyle = "{StaticResource ListViewItemStyle}"
ScrollViewer.HorizontalScrollBarVisibility="Hidden">
可观察的收藏
public ObservableCollection<Entry> TestEntries
{
get => new ObservableCollection<Entry>(_testEntries
.Where(x => x.Title.ToUpper().Contains(FilterText.ToUpper()))
.OrderByDescending(x => x.Date));
set
{
_testEntries = value;
OnPropertyChanged();
}
}
命令(删除项目)
private void ButtonDeleteCommandExecute()
{
var toDeleteEntries = TestEntries.Where(x => x.IsSelected);
toDeleteEntries.ToList().ForEach((obj) =>
{
TestEntries.Remove(obj as Entry);
});
}
希望有人能指出我正确的方向
答案 0 :(得分:0)
试试这个:
在ObservableCollection
中返回getter
的同一对象,以便notify
将Target
更新为@George Alexandria Suggested。
public ObservableCollection<Communication> TestEntries
{
get
{
return _testEntries;
}
set
{
_testEntries = value;
//OnPropertyChanged(); <-- of no use
}
}
由于您希望filter
中有listView
个数据:
TestEntries = new ObservableCollection<Communication>(_testEntries.Where(x=>x.Title.ToUpper().Contains(FilterText.ToUpper())).OrderByDescending(x=>x.Date).ToList());