'How to customize Collection View Selection Changed background color
I have the following code to display some data:
<StackLayout Margin="15,0,15,5" BackgroundColor="Transparent">
<CollectionView ItemsSource="{Binding DatabaseItems}" SelectionMode="Single" SelectionChanged="OnCollectionViewSelectionChanged" BackgroundColor="Transparent">
<CollectionView.ItemTemplate>
<DataTemplate>
<StackLayout>
<Frame BackgroundColor="#fff2d8" HorizontalOptions="Center" Margin="0,10,0,5" Padding="2" WidthRequest="350" CornerRadius="10">
<StackLayout BackgroundColor="#fff2d8">
<Label Text="{Binding Data1}" TextColor="Black" FontAttributes="Bold" HorizontalOptions="Center" Margin="0, 5, 0, 0" FontSize="20"/>
<Label Text="{Binding Data2}" TextColor="Black" Margin="10, 0, 0, 0" FontSize="15"/>
<Label Text="{Binding Data3}" TextColor="Black" Margin="10, 0, 0, 0" FontSize="15"/>
<Label Text="{Binding Data4}" TextColor="Black" Margin="10, 0, 0, 15" FontSize="15"/>
</StackLayout>
</Frame>
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</StackLayout>
As you can see, I have a Selection Changed event, so everytime I click it, it does something.
The problem is, everytime I click it, the background is orange, and i'd like it to be other color, black or white for example. I've tried a couple things I've seen online but I can't make it work, at least not with this code.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
