When I add a SelectionChanged function in the collection view, VisualStateManager does not work.
<ContentPage.Resources>
<Style TargetType="StackLayout">
<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>
When I add this code in CollectionView: SelectionChanged="OnCollectionViewSelectionChanged", the VisualStateManager stop to work. Does anyone know why?
The issue caused that the
SelectionChangedcould not get the selected element type likeStackLayoutorLabel. You could useTapGestureRecognizerinstead.Xaml:
Code behind:
Screenshot: