我是 WPf Datagrid 的新手。如果我在 datagrid 中选择一个单元格并按 Enter,我的要求应该更改为 readonly=false(可编辑)并且用户可以更改内容,如果他按 Enter 键,则单元格应该更改为 readonly = true (不可编辑)。
我的 xml 看起来像这样:
<DataGrid AutoGenerateColumns="False" Height="496" HorizontalAlignment="Left"
PreviewKeyDown="DgvMaterial_PreviewKeyDown" DataGridCell.Selected="DataGrid_select"
Name="DgvMaterial" VerticalAlignment="Top" Width="958" Margin="21,20,0,0"
ItemsSource="{Binding Path=., Mode=OneWay}"
AlternationCount="1" AlternatingRowBackground="#FFE9FFE9"
SelectionUnit="FullRow" CanUserResizeColumns="False" DataContext="{Binding}"
RowHeight="30" UseLayoutRounding="True"
RowHeaderWidth="0" OverridesDefaultStyle="False" ColumnHeaderHeight="30"
SelectionMode="Single" ScrollViewer.VerticalScrollBarVisibility="Auto"
FontFamily="MS Gothic" FontSize="12" CellStyle="{StaticResource Body_Content_DataGrid_Centering}"
IsHitTestVisible="True" SelectionChanged="DgvMaterial_SelectionChanged"
Loaded="DgvMaterial_Loaded" CellEditEnding="DgvMaterial_CellEditEnding" TabIndex="5"
SelectedIndex="-1" IsReadOnly="True">