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

Selection breaks after deleting item. #4293

Closed
grokys opened this issue Jul 14, 2020 · 1 comment · Fixed by #4294 or #4308
Closed

Selection breaks after deleting item. #4293

grokys opened this issue Jul 14, 2020 · 1 comment · Fixed by #4294 or #4308
Assignees
Labels

Comments

@grokys
Copy link
Member

grokys commented Jul 14, 2020

Selection in ListBox is currently broken if one deletes the currently selected item:

O7pxVVH2tD

The above gif shows a ListBox with single selection. If the currently selected item is deleted, a "ghost" selection moves to the subsequent item and is only removed when the item is selected and then unselected again.

@grokys grokys self-assigned this Jul 14, 2020
@grokys grokys added the bug label Jul 14, 2020
@grokys
Copy link
Member Author

grokys commented Jul 14, 2020

This is caused by the order of subscriptions to the source list between SelectionModel and SelectingItemsControl: SelectionModel needs to subscribe to CollectionChanged events before ItemsControl in order for the selection to be updated before updating the visual selection indication.

grokys added a commit that referenced this issue Jul 14, 2020
`SelectionModel` needs to subscribe to `CollectionChanged` on the items before `ItemsControl` in order for the selection to be correct when we come to setting the selected state.

Because `SelectionModel.Source` isn't subscribed during initialization in `ItemsChanged`, we also need to make sure we don't subscribe `ItemsControl` to the collection changes during initialization. Instead subscribe in `OnInitialized` (this requires a few tests to be rooted in order to be called).

Fixes #4293
@grokys grokys reopened this Jul 16, 2020
grokys added a commit that referenced this issue Jul 16, 2020
donandren added a commit to donandren/Avalonia that referenced this issue Oct 23, 2020
danwalmsley added a commit that referenced this issue Oct 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
1 participant