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