Skip to content

Apply IsSelected from items declared in XAML - #22363

Merged
MrJul merged 2 commits into
AvaloniaUI:mainfrom
Evan260:fix-combobox-item-isselected
Oct 6, 2026
Merged

MrJul merged 2 commits into
AvaloniaUI:mainfrom
Evan260:fix-combobox-item-isselected

Conversation

@Evan260

@Evan260 Evan260 commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

What does the pull request do?

Applies IsSelected set on an item declared in XAML as soon as the control is initialized.

What is the current behavior?

A ComboBoxItem written with IsSelected="True" isn't selected when the window opens. The flag is only read when the item's container is realized, and a ComboBox doesn't realize its items until the drop-down is opened, so the box stays blank and SelectedIndex stays at -1 until the user opens it once.

What is the updated/expected behavior with this PR?

Inline items marked as selected are read during initialization, so the selection is there from the start.

The sync that runs when a container is realized now only runs when the container and the control disagree. It passes toggleModifier: true, so without that check it would toggle the selection straight back off the first time the drop-down opened.

Fixed issues

Fixes #21571

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown

NuGet packages

The packages for this pull request have been published (workflow run):

@MrJul MrJul added bug backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch area-controls labels Oct 1, 2026
@MrJul
MrJul added this pull request to the merge queue Oct 6, 2026
Merged via the queue into AvaloniaUI:main with commit be44e32 Oct 6, 2026
12 checks passed
@Evan260
Evan260 deleted the fix-combobox-item-isselected branch October 6, 2026 17:38
grokys pushed a commit to Evan260/Avalonia that referenced this pull request Oct 7, 2026
* Add tests for a ComboBoxItem marked as selected in XAML

* Apply IsSelected from inline items before their containers are realized
MrJul pushed a commit that referenced this pull request Oct 9, 2026
* Add tests for a ComboBoxItem marked as selected in XAML

* Apply IsSelected from inline items before their containers are realized
@MrJul MrJul added backported-12.1.x and removed backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch labels Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ComboBoxItem.IsSelected="True" is not applied until the ComboBox is clicked

3 participants