Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ListBox with Extended SelectionMode "remembers" start of previous selection range separated by single item selection #406

Closed
clemarescx opened this issue Oct 7, 2021 · 0 comments · Fixed by #409
Labels
Milestone

Comments

@clemarescx
Copy link

To Reproduce
Steps to reproduce the behavior in the Showcase project:

  1. Go to ListBox > Bound (the default view when starting the project)
  2. In the LeftBoundListBox, select item 2
  3. Hold shift, and select item 10
    • Range 2 to 10 is selected, as expected
  4. Select a single item within the previous range by clicking without holding shift, e.g item 5
    • Only item 5 is selected, as expected
  5. Hold shift and click an item with index higher than previously selected item, e.g item 7
    • Range 2 to 7 is selected, which wasn't expected

Note: this does not occur when setting dd:DragDrop.DragSourceIgnore="True" on the ListBox.

Expected behavior
Only the items in the selected range should be selected.

Findings
A similar issue occurs "backwards":

  1. select item 10 first
  2. hold shift and select item 2
  3. select a single item 7
  4. hold shift and select item 5
    • range 10 to 5 will be selected

SelectionChanged event is raised multiple times when going from selected range to single selection

  • When selecting the single item between the two range selections, the SelectionChanged event on the ListBox is raised multiple times, each time removing a single item from SelectedItems, until only the single item is selected.
  • To view this, add the following handler to LeftBoundListBox:
    ListBoxSamples.xaml:
     <ListBox x:Name="LeftBoundListBox"
               ...
               SelectionChanged="LeftBoundListBox_OnSelectionChanged" />
    ListBoxSamples.xaml.cs:
    private void LeftBoundListBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        var selectedItems = this.LeftBoundListBox.SelectedItems.OfType<ItemModel>().ToList();
        var itemIndices = selectedItems.Select(svm => $"{svm.Index}");
        var indexList = string.Join(", ", itemIndices);
        Debug.WriteLine($"selected: : {indexList}");
    }
    When running the same sequence as described in To reproduce, the expected output will be:
    selected: : 2
    selected: : 2, 3, 4, 5, 6, 7, 8, 9, 10
    selected: : 3, 4, 5, 6, 7, 8, 9, 10
    selected: : 4, 5, 6, 7, 8, 9, 10
    selected: : 5, 6, 7, 8, 9, 10
    selected: : 5, 7, 8, 9, 10
    selected: : 5, 8, 9, 10
    selected: : 5, 9, 10
    selected: : 5, 10
    selected: : 5
    selected: : 5, 2, 3, 4, 6, 7
    

Demo of the sequence
pgkOKXaHWS

Desktop (please complete the following information):

  • OS: Microsoft Windows 10 Pro
  • Version 10.0.19043 Build 19043

Additional context
Tested with VS 2019 and VS 2022 Preview 4.1:

  • .NET Framework 4.5
  • .NET Framework 4.6.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants