Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the small of padding around the ListBoxItem?

I'm styling a listBox. i'm trying to clear the margins, so I realized which it, I set the padding of the style to 0 (left padding).

But I can still seeing some margin in it, and I need to have no margin in it? Does you know which would be the problem?

enter image description here

            <ListBox ItemsSource="{Binding Partitions}">
                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <Canvas />
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>

                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem">
                        <Setter Property="Padding" Value="0"/>
                        <Setter Property="Canvas.Top">
                            ...
                        </Setter>
                </Style>
                </ListBox.ItemContainerStyle>

I mean, I can see an extra space around the item and I can't handle it to modify to 0.

like image 389
Darf Zon Avatar asked Mar 25 '12 05:03

Darf Zon


1 Answers

That padding is hard-coded in the default template of the ListBox, you either need to override it or modify it at runtime (which i would not recommend).

<ControlTemplate TargetType="{x:Type ListBox}">
    <Border Name="Bd"
            Background="{TemplateBinding Background}"
            BorderBrush="{TemplateBinding BorderBrush}"
            BorderThickness="{TemplateBinding BorderThickness}"
            SnapsToDevicePixels="true"
            Padding="1"> <!-- Here -->
like image 119
H.B. Avatar answered Oct 18 '22 09:10

H.B.