我有一个WPF数据网格,它适用于我想要的,但每行都有两个可以编辑的单元格。是否可以在编辑行时将这两行放入编辑模式,然后在行编辑结束时触发更新/行失去焦点?目前,在每个单元格被编辑后,RowEditEnding触发,并且用户必须等待提交后重新绘制UI。我使用的代码是:WPF DataGrid全行编辑
private bool isManualEditCommit;
private void dg_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
{
if(e.EditAction!= DataGridEditAction.Commit)
return;
var newProd = dgLists.SelectedItem as IProduct;
if(newProd==null)
return;
worker = new BackgroundWorker();
worker.DoWork += (s, dwe) =>
{
... commit update
};
worker.RunWorkerCompleted += (s, rwe) =>
{
... refresh grid
};
worker.RunWorkerAsync();
}
/// <summary>
/// Commits edits when a cell edit ends.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.Windows.Controls.DataGridCellEditEndingEventArgs"/> instance containing the event data.</param>
private void dg_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) {
if (e.EditAction == DataGridEditAction.Commit)
{
if (!isManualEditCommit)
{
isManualEditCommit = true;
DataGrid grid = (DataGrid) sender;
grid.CommitEdit(DataGridEditingUnit.Row, true);
isManualEditCommit = false;
}
}
但并非所有单元格都进入编辑模式。每个单元格在接收焦点时显示它的CellEditingTemplate,但该行中的其他单元格具有标准的,不可编辑的控件。 – Echilon 2011-05-22 09:51:57