Skip to content

Custom selection styles for items in CollectionView are ignored when programmatically selecting an item #18933

@tschbc

Description

@tschbc

Description

Programmatically selecting an item in a CollectionView does not respect the VisualStateManager in its ItemTemplate (applied by styles or otherwise). Selecting the item as a user (tap / click) works.

Steps to Reproduce

  1. Create a new MAUI app and replace default views with a CollectionView. Set its SelectionMode to "Single." Subscribe to its "Loaded" event. Add a VisualStateManager to its ItemTemplate that changes the BackgroundColor to Aqua when Selected.

  2. Assign a list of strings to the CollectionView's ItemSource and, when its Loaded event fires, set the CollectionView's SelectedItem to the second string from the list.

  3. On Windows: When the CollectionView loads, the second item is selected with the default selection style:

image

Clicking a different item correctly applies the custom selection style:

image

  1. On iOS 17.0 simulator it's even worse. When the CollectionView loads and the second item is selected it just disappears:

image

Selecting a different item doesn't bring it back:

image

And when selecting a different item again, either the SelectionMode or VisualStateManager breaks, applying selection styles to multiple items:

image

Link to public reproduction project repository

https://github.com/tschbc/SelectionStyleIssue

Version with bug

8.0.3

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS, Windows

Affected platform versions

windows10.0.19041.0, iOS 17.0

Did you find any workaround?

No

Relevant log output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions