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
-
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.
-
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.
-
On Windows: When the CollectionView loads, the second item is selected with the default selection style:

Clicking a different item correctly applies the custom selection style:

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

Selecting a different item doesn't bring it back:

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

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
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
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.
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.
On Windows: When the CollectionView loads, the second item is selected with the default selection style:
Clicking a different item correctly applies the custom selection style:
Selecting a different item doesn't bring it back:
And when selecting a different item again, either the SelectionMode or VisualStateManager breaks, applying selection styles to multiple items:
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