Skip to content

Fix some issues on SelectingItemsControls when items or control changes visibility#20798

Open
timunie wants to merge 12 commits intoAvaloniaUI:masterfrom
timunie:ListBoxScrollToElementAfterHide
Open

Fix some issues on SelectingItemsControls when items or control changes visibility#20798
timunie wants to merge 12 commits intoAvaloniaUI:masterfrom
timunie:ListBoxScrollToElementAfterHide

Conversation

@timunie
Copy link
Collaborator

@timunie timunie commented Mar 3, 2026

What does the pull request do?

  • Fixes an issue where ListBox doesn't scroll selected item into view after becoming visible
  • Fixes an issue where ColorPicker gets out of sync with SelectedIndex @robloo please test the ColorPicker part if it makes sense to you.

What is the current behavior?

SelectingItemsControls with AlwaysSelected set can select invisible items by accident

What is the updated/expected behavior with this PR?

How was the solution implemented (if it's not obvious)?

Checklist

Breaking changes

ColorView API was changed by removing not needed protected void

Obsoletions / Deprecations

Fixed issues

Fixes #14718
Fixes #13736 (@robloo this should be the last issue to solve, so I'll close the rollup with this PR)

@MrJul MrJul added bug backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch labels Mar 3, 2026
@timunie timunie marked this pull request as draft March 4, 2026 07:26
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0062915-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@timunie timunie changed the title Fix AutoScrollToSelectedItem after ListBox got visible Fix some issues on SelectingItemsControls when items or control changes visibility Mar 4, 2026
The TabItem now handles the correct selection of only visible items
@timunie timunie force-pushed the ListBoxScrollToElementAfterHide branch from 429ebbb to b28138e Compare March 4, 2026 12:24
@timunie
Copy link
Collaborator Author

timunie commented Mar 4, 2026

@MrJul there is now one change that should not backport, but the fix itself can be backported
@robloo please review the ColorPicker changes. On ControlCatalog I can now set the SelectedIndex without issues.

@timunie timunie marked this pull request as ready for review March 4, 2026 12:26
@timunie timunie requested a review from Copilot March 5, 2026 18:55
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@timunie timunie requested a review from Copilot March 5, 2026 19:22
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0063036-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Contributor

@robloo robloo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments on the code changes but overall looks really good. I will have to find the time to test this later though. I've only looked at the code.

/// Finds the first visible and enabled index in the ItemsSource.
/// </summary>
/// <returns>the index of the first visible and enabled item, or -1 if none found</returns>
private int GetFirstVisibleAndEnabledIndex()
Copy link
Contributor

@robloo robloo Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll place general comments here. Without testing, my understanding of WPF is:

  1. Enabled=false tabs are still visible but can't be clicked. If there are NO other tabs the Enabled=False tab should be the one visible but with all it's content disabled.
  2. Visible=false tabs are completely hidden and removed from the control

Part 1 likely doesn't function the same since you are treating Enabled/Visible as equivalent -- they have slight differences.

Visible=false

  • Never visible in the tab strip, so can't be selected by the user
  • Never visible in the tab content (this is the needed fix)

Enabled=false

  • Always visible in the tab strip.... but with the disabled styling. Cannot be selected by the user, but can be selected as the default.
  • MAY BE visible in the tab content if there are NO other tab pages

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tabs can be selected programatically. I am not sure how to deal with that if really all tabs are either disabled or hidden. We should review this in the team before making an decision.

@timunie timunie added the needs-api-review The PR adds new public APIs that should be reviewed. label Mar 8, 2026
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0063092-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch bug needs-api-review The PR adds new public APIs that should be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AutoScrollToSelectedItem doesn't work if selection was set while the control was invisible ItemsControl / ListBox Issues Roll-up

5 participants