0
我新来WPf Datagrid。我的需求,如果我选择数据网格中的一个单元格,并按下输入它应该改为readonly = false(可编辑),用户可以更改内容,如果他再次按输入键单元格应该更改为readonly = true(不可编辑)。DataGrid编辑和只读行为wpf
我的XAML看起来像这样:
<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">
处理
DataGrid.PreviewKeyDown
和BeginEdit()
而且重点应保持在同一小区 – user1929251做您尝试使用'DataGridTemplateColumn'并指定'的观点CellTemplate'(例如'TextBlock')和'CellEditingTemplate'为编辑(例如'TextBox')? – dkozl