防止WPF DataGrid中单元格级别的制表位,但仍允许行具有制表位。

3
我希望阻止单个单元格的制表符,但允许行级制表符。
我认为我可以使用CellStyle在所有单元格上禁用IsTabStop。
<DataGrid.CellStyle>
    <Style TargetType="DataGridCell">
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="IsTabStop" Value="false"/>
    </Style>
</DataGrid.CellStyle>

但这样会防止行也有制表位

因此,我认为应该使用RowStyle在行上启用制表位

<DataGrid.RowStyle>
    <Style TargetType="DataGridRow">
        <Setter Property="IsTabStop" Value="true"/>
    </Style>
</DataGrid.RowStyle>

但这也没有用。
有人有什么想法吗?
1个回答

7
我的解决方案是这样的 -
为所有 DataGridCell 列将 IsTabStop 更改为 false 为我的主列,即 DataGridTemplateColumn 将 IsTabStop 更改为 true
<DataGrid.CellStyle>
    <Style TargetType="DataGridCell">
        <Setter Property="IsTabStop" Value="false"/>
    </Style>
</DataGrid.CellStyle>


<DataGrid.Columns>

    <DataGridTemplateColumn Header="File name" Width="435">

        <DataGridTemplateColumn.CellStyle>
            <Style TargetType="DataGridCell">
                <Setter Property="IsTabStop" Value="true"/>
                <Setter Property="BorderThickness" Value="0"/>
                <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
            </Style>
        </DataGridTemplateColumn.CellStyle>

    ...........

通过包含这行代码,我可以禁用点线方框边框。
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>

编辑*

算了,这太麻烦了。我想现在使用列表视图更有意义。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接