Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MAUI Collection View Selected Color

I’m working with .NET MAUI and have implemented a CollectionView in my application. I want to achieve that the selected items in the CollectionView either have no selection color or have a different selection color than orange on the platform Android. In iOS the default value of gray is okay

Is there a way to individually customize or disable the selection color for the items?

Tried setting the VisualStateManager

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<ContentPage.Resources>
        <Style TargetType="CollectionView">
            <Setter Property="VisualStateManager.VisualStateGroups">
                <VisualStateGroupList>
                    <VisualStateGroup x:Name="CommonStates">
                        <VisualState x:Name="Normal" />
                        <VisualState x:Name="Selected">
                            <VisualState.Setters>
                                <Setter Property="BackgroundColor" Value="Red"/>
                            </VisualState.Setters>
                        </VisualState>
                    </VisualStateGroup>
                </VisualStateGroupList>
            </Setter>
        </Style>
    </ContentPage.Resources>

>Solution :

Did you check the official document about Changing selected item color of CollectionView in the .net maui?

The official document said:

The Style that contains the Selected VisualState must have a TargetType property value that’s the type of the root element of the DataTemplate, which is set as the ItemTemplate property value.

So the TargetType should bethe root element of the DataTemplate in your project such as Grid, StackLayout and so on, not the CollectionView.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading