ListViewItemPresenter background has extra margin
See original GitHub issueDescribe the bug
Background of ListViewItemPresenter rendered with additional spaces. However, content uses the entire area of the presenter.
Reproduced on WindowsAppSDK 1.0.0. Normal on 0.8.*
Steps to reproduce the bug
Xaml:
<Grid Background="LightGray">
<ListView SelectionMode="None">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="BorderBrush" Value="Black" />
<Setter Property="BorderThickness" Value="0, 0, 0, 1" />
<Setter Property="Background" Value="DimGray" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<ListViewItemPresenter Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate>
<Border>
<TextBlock Text="{Binding}" />
</Border>
</DataTemplate>
</ListView.ItemTemplate>
<x:String>11111</x:String>
<x:String>22222</x:String>
<x:String>33333</x:String>
<x:String>44444</x:String>
<x:String>55555</x:String>
</ListView>
</Grid>
Expected behavior
If set background directly to DataTemplate:
<ListView.ItemTemplate>
<DataTemplate>
<Border Background="DimGray">
<TextBlock Text="{Binding}" />
</Border>
</DataTemplate>
</ListView.ItemTemplate>
Screenshots
No response
NuGet package version
No response
Windows app type
- UWP
- Win32
Device form factor
Desktop
Windows version
May 2020 Update (19041), May 2019 Update (18362)
Additional context
No response
Issue Analytics
- State:
- Created 2 years ago
- Reactions:6
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Remove the space padding margin around a ListViewItem
Except then your background color will have space around it since Background is on the object that now also has margin. Make sense?...
Read more >Unwanted padding on ListViewItem in .net MAUI
Is there any way to remove the unwanted padding? I'll include the picture for visualization (ListView has red background, and children have blue ......
Read more >ListViewItemPresenter Class (Microsoft.UI.Xaml.Controls. ...
Gets or sets the margin of the background displayed for pointer-over input actions in the ListView item cell, versus the cell. This property...
Read more >Question - Listview item margin
Hi, I'm customizing items style in the listview. However, the margin values are not reflected and in the debugger it is always 0....
Read more >ListView and GridView Templates for Windows (UWP)
It can be used to add borders, background or margin to every item in the ListView. The ItemContainerStyle also has a number of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@StephenLPeters
I filed https://stackoverflow.com/questions/74221139/remove-listviewitempresenter-border-in-microsoft-ui-xaml-listview before finding this bug report.
As reported there, there appears to be an additional
Border
element as a child of theListViewItemPresenter
, and it has aMargin
of4,2,4,2
.I’m very interested in knowing if there’s a way to remove this margin, since it has caused our dozens and dozens of
ListView
s to render improperly.Does anyone have a workaround for this?