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 (or SelectingItemsControl) selection change raises the Remove instead of Reset #17789

Open
MechWarrior99 opened this issue Dec 16, 2024 · 0 comments
Labels

Comments

@MechWarrior99
Copy link

Describe the bug

When a SelectingItemsControl (or specifically ListBox) is set to SelectionMode = Single, with an ObserivableCollection bound to the SelectedItems property. When selection changes, the action type for the event on the ObservableCollection is Remove instead of Reset. This is an issue if items that are not in the ItemsSource can be selected. (Like sharing selection between multiple ListBoxes)
As a note, the TreeView will raise the event with the Reset action instead, under the same conditions.

To Reproduce

  1. Create a default MVVM application.
  2. Replace the body of the MainView.axaml with the following
 <ListBox SelectedItems="{Binding SelectedItems}"
                 SelectionMode="Single">
       <ListBoxItem Content="Item 1"/>
        <ListBoxItem Content="Item 2"/>
        <ListBoxItem Content="Item 3"/>
        <ListBoxItem Content="Item 4"/>
</ListBox>
  1. Replace the body of MainViewModel.cs with the following
 public ObservableCollection<object> SelectedItems { get; set; }

  public MainViewModel()
  {
      SelectedItems = new ObservableCollection<object>();
      SelectedItems.CollectionChanged += (sender, args) =>
      {
          // Set break point here ^^^^^
      };
  }
  1. Set a break point where specified.
  2. Run in debug mode, change selection.
  3. Change selection a second time.

Expected behavior

When selection changes from an existing selection, args.Action should be NotifyCollectionChangedAction.Reset.

Avalonia version

11.2.2

OS

Windows

Additional context

No response

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

No branches or pull requests

1 participant