如何禁用DataGrid上列内的编辑内容

时间:2017-09-05 11:32:56

标签: c# wpf xaml datagrid

我想禁用我DataGrid内部的编辑内容,例如,如果用户点击双击,他可以立即编辑一个列,我想避免这样做......

我尝试通过编写IsReadOnly来设置DataGrid属性:

<DataGrid Grid.Row="1"  VerticalContentAlignment="Center" IsReadOnly="True">

但这对我不利,因为我想通过点击&#34;删除&#34;删除DataGrid中的行。按钮,如果我将此状态设置为我的数据网格

IsReadOnly="True"

然后我失去了这个功能......

但我想我可以以某种方式应用以下代码来禁用单元格..

<Style TargetType="{x:Type DataGridCell}">
    <Setter Property="IsReadOnly" Value="True" />
</Style>

但不幸的是,它不起作用:(

1 个答案:

答案 0 :(得分:1)

您可以将每列的IsReadOnly属性设置为true:

<DataGrid>
    <DataGrid.Columns>
        <DataGridTextColumn ... IsReadOnly="True" />
    </DataGrid.Columns>
</DataGrid>

这应禁用单元格的编辑,但仍允许删除行。