删除 WPF ListView 的“经典”缩进边框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1562867/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 21:06:08  来源:igfitidea点击:

Removing a WPF ListView's "classic" indented border

wpflistviewstylesborder

提问by M. Dudley

How can I remove the "classic" indented border from around my WPF ListViewcontrol? Setting its BorderThicknessto 0 does not get rid of it.

如何从 WPFListView控件周围删除“经典”缩进边框?将其设置BorderThickness为 0 并不能摆脱它。

回答by Nikos Tsokos

Don't know if its a former version of WPF, but on Visual studio 2008 the following is enough to remove all borders and colors of a listview control

不知道它是否是 WPF 的以前版本,但在 Visual Studio 2008 上,以下内容足以删除列表视图控件的所有边框和颜色

<ListView Background="Transparent" BorderThickness="0">

回答by Guy Starbuck

For a lot of the built-in WPF control styles, you need to override the ControlTemplate to get this level of control over the rendering.

对于很多内置的 WPF 控件样式,您需要覆盖 ControlTemplate 以获得对渲染的这种级别的控制。

Hereis the MSDN page that provides the ListView ControlTemplate, with instructions on how to use it -- basically you are inserting local copies of all the styles for the ListView control, which then override the default control look and feel.

是提供 ListView ControlTemplate 的 MSDN 页面,其中包含有关如何使用它的说明——基本上,您正在插入 ListView 控件的所有样式的本地副本,然后覆盖默认控件外观。

To get rid of the indented border, you will need to find the specific border definition in the control template that is causing the behavior you want to modify; there are several of them, but it should be easy enough to figure out which one is causing the indentation using trial and error and/or Snoop.

要摆脱缩进边框,您需要在控件模板中找到导致您想要修改的行为的特定边框定义;其中有几个,但是使用试错和/或Snoop找出导致缩进的原因应该很容易。

回答by Jo?o Carvalho

listview1.BorderStyle = BorderStyle.None