question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[iOS] CollectionView multi-select pre-selected item VisualState error

See original GitHub issue

Description

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

  1. Checkout https://github.com/minglu/iOSCollectionViewPreselectedTest
  2. Build and Run, Click the [Open Pre-selected Popup] button on the main page
  3. It will popup a CollectionView that is supposed to show 3 pre-selected states from the list with Primary BackgroundColor (but not)
  4. You can select any item to observe the bug
  5. 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:open
  • Created 8 months ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
PureWeencommented, Feb 2, 2023

@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.

0reactions
jinxinjuancommented, Jun 27, 2023

Verified this issue with Visual Studio Enterprise 17.7.0 Preview 2.0. Can repro on iOS platform with sample project. iOSCollectionViewPreselectedTest.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is up with capturing Xamarin CollectionView ...
There is a workaround for this issue, try using VisualStateManager to add the selected effect. <DataTemplate> <Frame> <VisualStateManager.
Read more >
Xamarin.Forms CollectionView Selection
When the SelectionMode property is set to Single , a single item in the CollectionView can be selected. When an item is selected, ......
Read more >
Any suggestions for a workaround for a CollectionView ...
Any suggestions for a workaround for a CollectionView selected item color? Hi everyone! In my application, I've added the DataTemplate for ...
Read more >
How To Change Background Color Of Selected Item In A ...
Change selected item color CollectionView has a Selected VisualState that can be used to initiate a visual change to the selected item in...
Read more >
Listview Selected Item Color
Right now on IOS its gray and I want it to be transparent if is selected. LISTVIEW selected item text color. As we...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found