question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ListViewItemPresenter background has extra margin

See original GitHub issue

Describe 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

image

If set background directly to DataTemplate:

<ListView.ItemTemplate>
   <DataTemplate>
      <Border Background="DimGray">
         <TextBlock Text="{Binding}" />
      </Border>
   </DataTemplate>
</ListView.ItemTemplate>
image

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:open
  • Created 2 years ago
  • Reactions:6
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
tylersouthardcommented, Oct 28, 2022

@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 the ListViewItemPresenter, and it has a Margin of 4,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 ListViews to render improperly.

0reactions
Slioncommented, Aug 15, 2023

Does anyone have a workaround for this?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found