Reputation: 2258
Each item in a WPF ListBox control seems to have a bit of left padding. How can I restyle to remove all padding?
Upvotes: 28
Views: 16260
Reputation: 178630
You can also style the ListBoxItem
s for a specific ListBox
as follows:
<ListBox>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Padding" Value="0"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
Upvotes: 51
Reputation:
I'm not quite sure WHY this is happening (it appears to be an issue NOT with the ListBox but the ListBoxItem. If you set the Background property of the LBI to red or some other color you can see that it is flush to the left side of the LB.
A quick hack is to set a negative margin for the button: Margin="-3 0 0 0" That might cause some unintended side effects but works visually...
edit A quick check confirmed that the LBI has default padding. You can turn it off like this:
<ListBoxItem Padding="0"><!-- content here k --></ListBoxItem>
Alternately, you can slap a style in your Window's resources that will remove this from all LBIs in your project (this might be pseudoxaml, but you get the idea):
<Style TargetType="ListBoxItem">
<Setter Property="Padding" Value="0"/>
</Style>
Upvotes: 5