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
SelectionChanged
could not get the selected element type likeStackLayout
orLabel
. You could useTapGestureRecognizer
instead.Xaml:
Code behind:
Screenshot: