Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WPF中的DataGridCell编辑模式问题_Wpf_Datagrid_Mouseevent_Wpf 4.0_Datagridcell - Fatal编程技术网

WPF中的DataGridCell编辑模式问题

WPF中的DataGridCell编辑模式问题,wpf,datagrid,mouseevent,wpf-4.0,datagridcell,Wpf,Datagrid,Mouseevent,Wpf 4.0,Datagridcell,问题是: 当我们想要编辑一个DataGridCell时,首先必须选择DataGridRow。我的意思是,要在DataGridRow.Current之外编辑DataGridCell,我们需要1单击单元格以选择第2行双击要进入编辑模式的单元格。我的问题是,我们如何只需单击一下就进入编辑模式?可能吗?首先,您可以将SelectionUnit=“Cell”设置为仅选择一个单元格 其次,可以使用键F2开始编辑 要在单击单元格时开始编辑,需要添加以下事件处理程序GotFocus: <DataGrid

问题是:


当我们想要编辑一个
DataGridCell
时,首先必须选择
DataGridRow
。我的意思是,要在
DataGridRow.Current
之外编辑
DataGridCell
,我们需要1<代码>单击单元格以选择第2行<代码>双击要进入编辑模式的单元格。我的问题是,我们如何只需单击一下就进入编辑模式?可能吗?

首先,您可以将
SelectionUnit=“Cell”
设置为仅选择一个
单元格

其次,可以使用键F2开始编辑

要在单击
单元格时开始编辑,需要添加以下事件处理程序
GotFocus

<DataGrid Name="MyDataGrid" SelectionUnit="Cell" GotFocus="MyDataGrid_GotFocus" ...>
private void MyDataGrid_GotFocus(object sender, RoutedEventArgs e)
{     
    if (e.OriginalSource.GetType() == typeof(DataGridCell))
    {            
        DataGrid MyDataGrid = (DataGrid)sender;

        if ((MyDataGrid != null) && (MyDataGrid.IsReadOnly == false))
        {
            MyDataGrid.BeginEdit(e);
        }
    }
}