It's a combination of BorderThickness
and Padding
from the Border
element (each contribute to 2px. 1px from left and 1px from right).
You can set
<ListView BorderThickness="0">
and loose 2px, however Padding
atleast on Windows-8 is set directly on the Border
control in the default Template and would not take any effect if set directly on the ListView
extract from default Style
for ListView
<ControlTemplate TargetType="{x:Type ListView}">
<Border x:Name="Bd"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="1"
SnapsToDevicePixels="true">
simplest option is to provide a custom Style
where you tweak that Padding
value to 0. You can also choose to use Behavior's and get a reference to the Border control and override padding in code.
If you choose the option of code-behind to override Padding
a very rough way to set the padding could be like:
public MainWindow()
{
InitializeComponent();
Loaded += (sender, args) => {
var border = (Border)lv.Template.FindName("Bd", lv);
border.Padding = new Thickness(0);
};
}
and your xaml:
<ListView x:Name="lv"
BorderThickness="0">