[iOS] CollectionView multi-select pre-selected item VisualState error
See original GitHub issueDescription
I think this is a similar issue to Xamarin.Forms #9511, CollectionView [SelectedItems] initially receives/contains correct pre-selected items passed from ViewModel, selected item visual state is “Selected” but still shows “normal” style until the user selects an item, Suddenly all selected items show correct “Selected” style, but you still have to select it twice to deselect it, and it only happens to iOS, macOS.
I tried the behavior workaround suggested in the xamarin.forms issue above, it’s better but somehow all pre-selected items are correctly showing “Selected” background color except the first item, also if you scroll away from the list, the style changes back to “normal” when you scroll back. so it doesn’t work for me (i commented out in the testing repo)
Steps to Reproduce
- Checkout https://github.com/minglu/iOSCollectionViewPreselectedTest
- Build and Run, Click the [Open Pre-selected Popup] button on the main page
- It will popup a CollectionView that is supposed to show 3 pre-selected states from the list with Primary BackgroundColor (but not)
- You can select any item to observe the bug
- If you click [Apply] it will return to the main page and alert actual selected items in string list
<VisualStateManager.VisualStateGroups>
<VisualStateGroupList>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="Selected">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="{StaticResource Primary}" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</VisualStateManager.VisualStateGroups>
List<string> s = new List<string>()
{
"FL",
"CA",
"IN",
"PA",
"TX",
"CO",
"DE",
"GA",
"ID",
"IL"
};
List<string> ss = new List<string>()
{
"FL",
"PA",
"GA"
};
States = new ObservableCollection<object>(s);
SelectedStates = new ObservableCollection<object>(ss);
Link to public reproduction project repository
https://github.com/minglu/iOSCollectionViewPreselectedTest
Version with bug
7.0 (current)
Last version that worked well
Unknown/Other
Affected platforms
iOS, macOS
Affected platform versions
iOS 16.3, macOS 12.6.3
Did you find any workaround?
No
Relevant log output
No response
Issue Analytics
- State:
- Created 8 months ago
- Reactions:2
- Comments:6 (1 by maintainers)
@minglu this is mostly likely fixed with the next SR of MAUI
You can test on the preview builds of MAUI or you can wait for it to reach stable.
Verified this issue with Visual Studio Enterprise 17.7.0 Preview 2.0. Can repro on iOS platform with sample project. iOSCollectionViewPreselectedTest.