如何在WPF DataGrid中禁用行选择
我目前在WPF中有一个DataGrid,它会自动高亮显示网格的第一行(如附图所示)。有没有办法禁用第一行的自动高亮显示。首先尝试以下方法:如何在WPF DataGrid中禁用行选择,wpf,datagridview,Wpf,Datagridview,我目前在WPF中有一个DataGrid,它会自动高亮显示网格的第一行(如附图所示)。有没有办法禁用第一行的自动高亮显示。首先尝试以下方法: <DataGrid IsSynchronizedWithCurrentItem = "False" ...> 如果不起作用,则可以尝试禁用焦点: 像这样: <Style x:Key="UnfocusableRow" TargetType="DataGridRow">
<DataGrid IsSynchronizedWithCurrentItem = "False" ...>
如果不起作用,则可以尝试禁用焦点:
像这样:
<Style x:Key="UnfocusableRow" TargetType="DataGridRow">
<Setter Property="Focusable" Value="False"/>
</Style>
<DataGridTextColumn RowStyle="{StaticResource UnfocusableRow}" />
或:
但是您应该知道,如果关闭焦点,您将无法查看或选择数据网格中的行。
如果要选择数据网格中的行,则“关闭焦点”选项将不适用于您
<DataGrid>
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="IsEnabled" Value="False"/>
</Style>
</DataGrid.RowStyle>
</DataGrid>