6

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.

Darf Zon
  • 6,268
  • 20
  • 90
  • 149
  • 1
    What is your full code? I plugged this into a basic Grid and do not get that problem – Justin Pihony Mar 25 '12 at 05:16
  • 1
    Possible [duplicate](http://stackoverflow.com/questions/1351605/where-are-the-margins-padding-set-on-a-wpf-listview-gridview). See the second answer in the question. – NVM Mar 25 '12 at 05:52

1 Answers1

3

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 -->
Community
  • 1
  • 1
H.B.
  • 166,899
  • 29
  • 327
  • 400