Darf Zon
Darf Zon

Reputation: 6378

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.

Upvotes: 6

Views: 3863

Answers (1)

brunnerh
brunnerh

Reputation: 185538

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 -->

Upvotes: 3

Related Questions