How to remove the small of padding around the ListBoxItem?

只愿长相守 提交于 2019-12-07 01:57:11

问题


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?

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


回答1:


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


来源:https://stackoverflow.com/questions/9858071/how-to-remove-the-small-of-padding-around-the-listboxitem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!