Hello,
Welcome to our Microsoft Q&A platform!
We can also use VisualStateManager.VisualStateGroups
to achieve the function. Try adding x:Name
for the Label
view and then use <Setter TargetName="xx" />
to set style for the label.
Check the code:
<CollectionView SelectionMode="Single" ...>
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup Name="CommonStates">
<VisualState Name="Normal" />
<VisualState Name="Selected">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Yellow" />
<Setter TargetName="_label" Property="Label.TextColor" Value="Red" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Label x:Name="_label" Text="{Binding xx}"/>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
Best Regards,
Jarvan Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.