PEK
PEK

Reputation: 4338

Higlight item in CollectionView when tapped

I have a basic CollectionView:

<CollectionView x:Name="ItemsList" SelectionMode="Single">
    <CollectionView.ItemTemplate>
        <DataTemplate>
            <Grid HeightRequest="80">
                <Label Text="Hello world" VerticalOptions="Center"/>
            </Grid>
        </DataTemplate>
    </CollectionView.ItemTemplate>
</CollectionView>
public MainPage()
{
    InitializeComponent();

    ItemsList.ItemsSource = new List<string>() { "1", "2", "3", "4" };
}

On Android, when the item is tapped you will get a simple tap effect:

Tap effect

I want to keep this effect. But if I change the background color according to the documentation:

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

The tap effect disappears. Is there some other way to do this?

Upvotes: 0

Views: 676

Answers (1)

Guangyu Bai - MSFT
Guangyu Bai - MSFT

Reputation: 4606

You can use the Background instead of using the BackgroundColor and the effect will back.

<Setter Property="Background" Value="LightSkyBlue"/>

Upvotes: 1

Related Questions