如何隐藏 wpf 数据网格行选择器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2865505/
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
How Do I Hide wpf datagrid row selector
提问by Tim Almond
I'm using the WPF DataGrid control to show some details and a select button, and I don't need the gray selector column down the left-hand side. It's also ruining the beauty of my design.
我正在使用 WPF DataGrid 控件来显示一些详细信息和一个选择按钮,我不需要左侧下方的灰色选择器列。这也破坏了我设计的美感。
Is there a way to remove it, or how can I style it to match if not?
有没有办法删除它,或者如果没有,我如何设计它以匹配?
回答by George Mavritsakis
Instead of setting the Width you can completely hide the row headers by setting on the DataGrid
您可以通过在 DataGrid 上设置来完全隐藏行标题,而不是设置 Width
HeadersVisibility="Column"
回答by slugster
Use the RowHeaderWidth
property:
使用RowHeaderWidth
属性:
<my:DataGrid RowHeaderWidth="0" AutoGenerateColumns="False" Name="dataGrid1" />
Note that you can also specify a style or template for it also, should you decide you really do like it and want to keep it because you can do something cool with it.
请注意,您也可以为其指定样式或模板,如果您决定真的喜欢它并想要保留它,因为您可以用它做一些很酷的事情。
回答by Maghalakshmi Saravana
To remove the Row header(Gray field) in Datagrid in WPF
在 WPF 中删除 Datagrid 中的行标题(灰色字段)
<DataGrid x:Name="TrkDataGrid" HeadersVisibility="Column">
</DataGrid>
To remove or hide the Column Header in DataGrid WPF
删除或隐藏 DataGrid WPF 中的列标题
<DataGrid x:Name="TrkDataGrid" HeadersVisibility="Row">
</DataGrid>
To remove or hide both Column and Row Header in DataGrid WPF
删除或隐藏 DataGrid WPF 中的列和行标题
<DataGrid x:Name="TrkDataGrid" HeadersVisibility="None">
</DataGrid>
回答by Frank Kotulak
Had the same problem.
有同样的问题。
Looks like the RowHeaderWidth is not supported in XAML BUT you can specify in the code behind right after the bind and it takes out that crappy selector column.
看起来 XAML 中不支持 RowHeaderWidth,但是您可以在绑定后的代码中指定,并取出那个糟糕的选择器列。
grdName.RowHeaderWidth = 0
grdName.RowHeaderWidth = 0