Search code examples
wpfxamllayoutlistboxitemitemtemplate

Why is the ListBoxItem content indented to the left?


I am sure this is something only my newb-ness can create, but, as seen in the screenshot, the border specified in the code snippet renders slightly indented from the left:

Here is the code for the data template:

    <DataTemplate x:Key="itemsTemplate">
        <Border BorderThickness="1,0,0,1" BorderBrush="Black" >
            <TextBlock Text="{Binding DisplayString}" TextWrapping="Wrap" Cursor="Hand" FontFamily="Tahoma" />
        </Border>
    </DataTemplate>

I added the border on the left to better illustrate the problem. What I really want is the bottom border to extend the full width of the ListboxItem. Why is it indented? How do I fix this?

Thanks!


Solution

  • In addition to DataTemplate you should declare this Style:

                <Style TargetType="ListBoxItem">
                    <Setter Property="Padding"
                            Value="0"/>
                </Style>