假设我有一个数据网格。假设所有列都是模板列。当任何单元格获得焦点时,我希望它进入编辑模式。
我到目前为止尝试过的:
我已经创建了一个DataGridCell样式,如下所示:
在窗口的代码后台中:
<Style TargetType="{x:Type DataGridCell}">
<EventSetter Event="GotFocus" Handler="DataGridCell_GotFocus" />
</Style>
在窗口的代码后台中:
private void DataGridCell_GotFocus(object sender, RoutedEventArgs e)
{
DataGridCell cell = sender as DataGridCell;
if (cell != null && !cell.IsEditing && !cell.IsReadOnly)
{
cell.IsEditing = true;
}
}
以上尝试存在的问题:
我必须单击单元格才能将其置于编辑模式。