Skip to content

SelectingItemsControl overwrites its own SelectedIndex value at startup #22133

Description

@TomEdwardsEnscape

Describe the bug

#20798 introduces a change in behaviour which breaks our application. We want the default selected item of a SelectingItemsControl to be a hidden item at index 0, but now the first visible and enabled index is forcibly selected during startup.

It's legal to have a hidden item selected: we can still programatically select the hidden item at index 0. But now, Avalonia picks a fight with us about this when the control is first created.

The new behaviour occurs even if SelectedIndex="0" has been specified.

To Reproduce

<TabStrip SelectedIndex="0">
  <TabStripItem IsVisible="False" Content="HELLO"/>
  <TabStripItem Content="WORLD"/>
</TabStrip>

The selected item will be "WORLD", even though I specified that it should be "HELLO".

You can re-select index 0 after the TapStrip has fully initialised, but at this point the side-effects of selecting index 1 have already occurred.

Expected behavior

The first item of a SelectingItemsControl is selected by default even if that item is hidden or disabled. Don't try to behave as if the user interacted with the control, they didn't!

If this new behaviour really is the intent, than at the very least the value of SelectedIndex should be respected so that the initial auto-selection of a visible+enabled item can be avoided.

Avalonia version

12.1.1

OS

No response

Additional context

No response

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-needs-reviewThe PR adds new public APIs that should be reviewed.bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions