Andy
Andy

Reputation: 1163

Padding issues with a WPF ListBox

In my application, I defined a DataTemplate for a ListBox to be a grid with a stretched border, and with a label inside it. For some reason, I've got the following result:

alt text http://dl.getdropbox.com/u/829214/q1.gif

As you can see, there is a padding between the ListBox border, and the item border, and this "padding" is marked when the item is selected. What property should I change to solve it?

Edited:

Kent's answer made me realize, that the border in my DataTemplate is placed inside the item container (list box item), and not replacing it as I thought. Eventually, I set the padding in the item container style to be 0, and my problem was solved.

Upvotes: 3

Views: 1053

Answers (1)

Kent Boogaart
Kent Boogaart

Reputation: 178810

I can't see the image because of a proxy issue, but I think you just need to set the background of the container:

<ListBox>
    <ListBox.ItemContainerStyle>
        <Setter Property="Background" Value="White"/>
    </ListBox.ItemContainerStyle>
</ListBox>

If you want the selection highlight to show outside the padded area, just set the Background back to null in the child container.

Upvotes: 2

Related Questions