如何删除ListBoxItem周围的小填充?

Dar*_*Zon 6 c# wpf xaml styles listbox

我正在设计一个listBox.我正在尝试清除边距,所以我意识到它,我将样式的填充设置为0(左边填充).

但我仍然可以看到它的一些余量,我需要没有余量吗?你知道哪个会出问题吗?

在此输入图像描述

            <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>
Run Code Online (Sandbox Code Playgroud)

我的意思是,我可以看到项目周围有一个额外的空间,我无法处理它修改为0.

H.B*_*.B. 3

该填充是硬编码在 的默认模板ListBox中,您需要覆盖它或在运行时修改它(我不建议这样做)。

<ControlTemplate TargetType="{x:Type ListBox}">
    <Border Name="Bd"
            Background="{TemplateBinding Background}"
            BorderBrush="{TemplateBinding BorderBrush}"
            BorderThickness="{TemplateBinding BorderThickness}"
            SnapsToDevicePixels="true"
            Padding="1"> <!-- Here -->
Run Code Online (Sandbox Code Playgroud)