【问题标题】:How to remove the small of padding around the ListBoxItem?如何删除 ListBoxItem 周围的小填充?
【发布时间】:2012-04-09 03:02:50
【问题描述】:

我正在设计一个列表框。我正在尝试清除边距,所以我意识到了它,我将样式的填充设置为 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>

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

【问题讨论】:

  • 你的完整代码是什么?我将它插入到一个基本的网格中并没有遇到这个问题
  • 可能duplicate。请参阅问题中的第二个答案。

标签: c# wpf xaml listbox styles


【解决方案1】:

该填充在ListBoxdefault template 中是硬编码的,您要么需要覆盖它,要么在运行时修改它(我会推荐)。

<ControlTemplate TargetType="{x:Type ListBox}">
    <Border Name="Bd"
            Background="{TemplateBinding Background}"
            BorderBrush="{TemplateBinding BorderBrush}"
            BorderThickness="{TemplateBinding BorderThickness}"
            SnapsToDevicePixels="true"
            Padding="1"> <!-- Here -->

【讨论】:

    猜你喜欢
    • 2013-01-07
    • 2013-07-31
    • 2018-03-22
    • 2014-01-30
    • 1970-01-01
    • 1970-01-01
    • 2017-02-22
    • 2017-11-23
    • 1970-01-01
    相关资源
    最近更新 更多