private void AllSelectCheckBox_OnClick(object sender, RoutedEventArgs e) { var isSelected = AllSelectCheckBox.IsChecked ?? false; if (isSelected) { CleanUpListBox.SelectAll(); } else { CleanUpListBox.UnselectAll(); } }
/// <summary> /// Shift多选 /// </summary> /// <param name="selectedListBoxItem"></param> private void SettleSelectedItemsForShift(ListBoxItem selectedListBoxItem) { int currentSelectIndex = CleanUpListBox.ItemContainerGenerator.IndexFromContainer(selectedListBoxItem); if (_previousSelectIndexForEditing >= 0 && currentSelectIndex >= 0) { int startNum = _previousSelectIndexForEditing; int endNum = currentSelectIndex; //Shift多选,删除其余选中 CleanUpListBox.UnselectAll(); //按顺序添加SelectedItems--因shift多选,listBox自带的选中项列表顺序混乱。 bool isAssending = endNum - startNum > 0; if (isAssending) { for (int i = startNum; i <= endNum; i++) { //多选模式下,当前MouseDown之后会触发SelctionChanged if (i == currentSelectIndex) { continue; } CleanUpListBox.SelectedItems.Add(CleanUpListBox.Items[i]); } } else { for (int i = startNum; i >= endNum; i--) { //多选模式下,当前MouseDown之后会触发SelctionChanged if (i == currentSelectIndex) { continue; } CleanUpListBox.SelectedItems.Add(CleanUpListBox.Items[i]); } } } }