如何在wpf中禁用xamdatagrid单元格编辑
本文关键字:xamdatagrid 单元格 编辑 wpf | 更新日期: 2023-09-27 18:14:53
我使用了xamdatagrid cellupdated事件,在该事件中,我必须在编辑中禁用特定的单元格,并希望在获得API调用的响应后启用它,问题是当我禁用它后启用单元格时,光标不会设置在正确的位置。
private async void RenewDataGrid_OnCellUpdated(object sender, CellUpdatedEventArgs e)
{
row.Cells[4].IsEnabled = false;
await datacontext.CalculateFdtotalAmount();
row.Cells[4].IsEnabled = true;
}
我在函数调用中使用XamDataGrid时遇到过类似的问题。我通过处理语句解决了这个问题,就像处理旧窗口的PeekMessage一样。要做到这一点,请尝试这样做:
private async void RenewDataGrid_OnCellUpdated(object sender, CellUpdatedEventArgs e)
{
row.Cells[4].IsEnabled = false;
DoEvents();
await datacontext.CalculateFdtotalAmount();
DoEvents();
row.Cells[4].IsEnabled = true;
}
public object ExitFrame(object f)
{
((DispatcherFrame)f).Continue = false;
return null;
}
public void DoEvents()
{
DispatcherFrame frame = new DispatcherFrame();
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background,
new DispatcherOperationCallback(ExitFrame), frame);
Dispatcher.PushFrame(frame);
}