我想禁用我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>
但不幸的是,它不起作用:(
答案 0 :(得分:1)
您可以将每列的IsReadOnly
属性设置为true:
<DataGrid>
<DataGrid.Columns>
<DataGridTextColumn ... IsReadOnly="True" />
</DataGrid.Columns>
</DataGrid>
这应禁用单元格的编辑,但仍允许删除行。