Description
openedon Feb 8, 2023
Description
On WinUI:
CollectionView's native ListViewItems have default PointerOver state which applies gray background on the items.
This blocks customizations in the PointerOver state in the ItemTemplate of the CollectionView, especially when using Color with alpha.
Steps to Reproduce
Case 1:
- Add CollectionView with SelectionMode="Single".
<CollectionView HeightRequest="500" x:Name="colView" SelectionMode="Single"/>
- Add ItemsSource to the CollectionView.
var items = new[] { "Item 1", "Item 2", "Item 3" };
this.colView.ItemsSource = items;
- Run the app in WinUI
Expected: When hovering over the items there should be no change in the visual state.
Actual: When hovering over the items there is a grey background color applied.
Case 2:
- Add CollectionView with SelectionMode="Single".
- Add ItemsSource to the CollectionView.
var items = new[] { "Item 1", "Item 2", "Item 3" };
this.colView.ItemsSource = items;
- Add ItemTemplate containing a Label.
- Set VisualStateManager.VisualStateGroups to the Label and in the PointerOver state change the BackgroundColor of the Label to some Color (with or without with alpha).
<CollectionView.ItemTemplate>
<DataTemplate>
<Label Text="{Binding .}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroupList>
<VisualStateGroup Name="CommonStates">
<VisualState Name="Normal" />
<VisualState Name="PointerOver">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="#40FFFF00"/>
<Setter Property="TextColor" Value="Purple" />
</VisualState.Setters>
</VisualState>
<VisualState Name="Disabled"/>
<VisualState Name="Selected"/>
</VisualStateGroup>
</VisualStateGroupList>
</VisualStateManager.VisualStateGroups>
</Label>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
- Run the app in WinUI
Expected: When hovering over the Labels inside the items if the CollectionView only the set in point 4 color should be seen.
Actual: When hovering over the Labels inside the items if the CollectionView the default native ListViewItem pointerover background color is displayed, as well as the set color in step 4. If the color from point 4 has alpha the grey color of the item is seen through due to the transparency.
Link to public reproduction project repository
https://github.com/telerik/ms-samples/tree/main/Maui/CollectionViewDefaultPointerOver_WinUI
Version with bug
7.0 (current)
Last version that worked well
Unknown/Other
Affected platforms
Windows
Affected platform versions
Windows SDK 10.0.19041
Did you find any workaround?
No
Relevant log output
No response