摆脱 ListView 中 1 像素的填充/边框间隙?

发布于 2024-11-28 23:59:48 字数 222 浏览 3 评论 0原文

看看这个!
打破!
我真的需要摆脱这个!
看说明!

<ListView Name="list" BorderThickness="0">

我该如何修复它?
这种间隙不仅发生在滚动条上,也发生在有或没有任何视图的项目上。

Look at this!
Breaking!
I really need to get rid of this!
Look at the delcaration!

<ListView Name="list" BorderThickness="0">

How do I fix it?
This gap doesn't only happen to the scrollbar, it also happens to the items, with or WITHOUT any views.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不乱于心 2024-12-05 23:59:49

如果你有 Blend,这个问题会更容易修复。如果没有,可以免费试用。您必须为您在该列表中使用的滚动查看器生成控件模板的副本。从那里您可以编辑滚动条的模板。

一旦您接触到滚动条模板,它就会有几个级别的模板深度。 ListView 模板>ItemsPresenter(在本例中为包裹面板)模板> ScrollViewer 模板 >滚动条模板。

This would be easier to fix in Blend if you have it. if not there is a free trial. You will have to generate a copy of the control template for the scrollviewer that you are using in that list. From there you can edit the template for the ScrollBar.

The scroll bars template is going to be several levels of templates deep once you get to it. ListView Template>ItemsPresenter (In this case a Wrap Panel) Template> ScrollViewer Template > ScrollBar Template.

梦毁影碎の 2024-12-05 23:59:48

看起来像是 Template 中的问题,很可能是内部控件的属性,该属性未绑定到 ListBox 向您公开的任何属性。

Vercas 编辑:我发现了问题。
这是ListView的模板:

<ControlTemplate x:Key="ListView" TargetType="ListBox">
    <Border Background="{TemplateBinding Control.Background}" BorderBrush="{TemplateBinding Control.BorderBrush}" BorderThickness="{TemplateBinding Control.BorderThickness}" Name="Bd" Padding="1" SnapsToDevicePixels="True">
        <ScrollViewer Focusable="False" Padding="{TemplateBinding Control.Padding}">
            <ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
        </ScrollViewer>
    </Border>
    <ControlTemplate.Triggers>
        <Trigger Property="UIElement.IsEnabled" Value="False">
            <Setter Property="Border.Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
        </Trigger>
        <Trigger Property="ItemsControl.IsGrouping" Value="True">
            <Setter Property="ScrollViewer.CanContentScroll" Value="False" />
        </Trigger>
    </ControlTemplate.Triggers>
</ControlTemplate>

只需将Border的Padding更改为0即可。
如果您不想费心寻找房产,这就是结果。

<ControlTemplate x:Key="ListView" TargetType="ListBox">
    <Border Background="{TemplateBinding Control.Background}" BorderBrush="{TemplateBinding Control.BorderBrush}" BorderThickness="{TemplateBinding Control.BorderThickness}" Name="Bd" Padding="0" SnapsToDevicePixels="True">
        <ScrollViewer Focusable="False" Padding="{TemplateBinding Control.Padding}">
            <ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
        </ScrollViewer>
    </Border>
    <ControlTemplate.Triggers>
        <Trigger Property="UIElement.IsEnabled" Value="False">
            <Setter Property="Border.Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
        </Trigger>
        <Trigger Property="ItemsControl.IsGrouping" Value="True">
            <Setter Property="ScrollViewer.CanContentScroll" Value="False" />
        </Trigger>
    </ControlTemplate.Triggers>
</ControlTemplate>

不要忘记将此模板添加到您的 ListView 中!

Looks like a problem in the Template, most likely a property of an internal control which is not bound to any of the properties the ListBox exposes to you.

Edit by Vercas: I have found the problem.
This is the template of the ListView:

<ControlTemplate x:Key="ListView" TargetType="ListBox">
    <Border Background="{TemplateBinding Control.Background}" BorderBrush="{TemplateBinding Control.BorderBrush}" BorderThickness="{TemplateBinding Control.BorderThickness}" Name="Bd" Padding="1" SnapsToDevicePixels="True">
        <ScrollViewer Focusable="False" Padding="{TemplateBinding Control.Padding}">
            <ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
        </ScrollViewer>
    </Border>
    <ControlTemplate.Triggers>
        <Trigger Property="UIElement.IsEnabled" Value="False">
            <Setter Property="Border.Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
        </Trigger>
        <Trigger Property="ItemsControl.IsGrouping" Value="True">
            <Setter Property="ScrollViewer.CanContentScroll" Value="False" />
        </Trigger>
    </ControlTemplate.Triggers>
</ControlTemplate>

Just change the Padding of the Border to 0 and you're done.
Here is the result if you don't want to bother finding the property.

<ControlTemplate x:Key="ListView" TargetType="ListBox">
    <Border Background="{TemplateBinding Control.Background}" BorderBrush="{TemplateBinding Control.BorderBrush}" BorderThickness="{TemplateBinding Control.BorderThickness}" Name="Bd" Padding="0" SnapsToDevicePixels="True">
        <ScrollViewer Focusable="False" Padding="{TemplateBinding Control.Padding}">
            <ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
        </ScrollViewer>
    </Border>
    <ControlTemplate.Triggers>
        <Trigger Property="UIElement.IsEnabled" Value="False">
            <Setter Property="Border.Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
        </Trigger>
        <Trigger Property="ItemsControl.IsGrouping" Value="True">
            <Setter Property="ScrollViewer.CanContentScroll" Value="False" />
        </Trigger>
    </ControlTemplate.Triggers>
</ControlTemplate>

Don't forget to add this template to your ListView!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文