[英]Sorting ListBox items clears selection
I have a ListBox with 我有一个列表框
IsSynchronizedWithCurrentItem="True"
IsSynchronizedWithCurrentItem =“ True”
Problem is if I select more than one item and change sorting order I end up with only one item selected. 问题是,如果我选择了多个项目并更改了排序顺序,我最终只会选择一个项目。
private ICollectionView FileCollectionView;
FileCollectionView = CollectionViewSource.GetDefaultView(FileCollection);
this.FilesLB.ItemsSource = CollectionViewSource.GetDefaultView(FileCollectionView);
ObservableCollection<FileData> _fileCollection = new ObservableCollection<FileData>();
public ObservableCollection<FileData> FileCollection
{ get { return _fileCollection; } }
private void SortFiles()
{
using (FileCollectionView.DeferRefresh())
{
FileCollectionView.SortDescriptions.Clear();
FileCollectionView.SortDescriptions.Add(new SortDescription(t.SortFiles.SortBy, t.SortFiles.SortDirection));
}
Why is that happening and how can I fix it? 为什么会发生这种情况,我该如何解决?
Because you are clearing the list. 因为您正在清除列表。 Fix it by storing the selection and reselecting it after you refilled the list.
通过存储选择并在重新填写列表后重新选择它来修复它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.