private void TagTreeView_TagCheckChanged(object sender, TagCheckChangedEventArgs e) { IEnumerable <FileInfo> result; if (tagTreeView.SelectedTag.Count == 0) { result = files.ToList(); } else { result = tagTreeView.SelectedTag .Join(mappers, x => x.Id, y => y.TagId, (x, y) => y) .Join(files, x => x.FileId, y => y.Id, (x, y) => y) .Distinct() .ToList(); } var needAdd = result.Except(fileListView.ItemsSource as BindingList <FileInfo>).ToArray(); var needDel = (fileListView.ItemsSource as BindingList <FileInfo>).Except(result).ToArray(); foreach (var del in needDel) { (fileListView.ItemsSource as BindingList <FileInfo>).Remove(del); } foreach (var add in needAdd) { (fileListView.ItemsSource as BindingList <FileInfo>).Add(add); } }
/// <summary> /// 事件->TagTree->选择Tag变化 /// </summary> /// <param name="selectedTags"></param> private void TagTree_TagCheckChanged(object sender, TagCheckChangedEventArgs e) { if (e.Tags.Count() == 0) { (fileList.ItemsSource as BindingList <FileInfo>).Clear(); foreach (var item in files) { (fileList.ItemsSource as BindingList <FileInfo>).Add(item); } } else { (fileList.ItemsSource as BindingList <FileInfo>).Clear(); e.Tags .Join(mappers, x => x.Id, y => y.TagId, (x, y) => y.FileId) .Join(files, x => x, y => y.Id, (x, y) => y) .Distinct() .ToList() .ForEach(item => (fileList.ItemsSource as BindingList <FileInfo>).Add(item)); } }