C# 如何在wpf中禁用xamdatagrid单元格编辑
我使用了xamdatagrid cellupdated事件,在该事件中,我必须在编辑时禁用特定单元格,并希望在收到API调用响应后启用它,问题是当我在禁用单元格后启用该单元格时,光标无法设置在正确的位置C# 如何在wpf中禁用xamdatagrid单元格编辑,c#,wpf,mvvm,infragistics,C#,Wpf,Mvvm,Infragistics,我使用了xamdatagrid cellupdated事件,在该事件中,我必须在编辑时禁用特定单元格,并希望在收到API调用响应后启用它,问题是当我在禁用单元格后启用该单元格时,光标无法设置在正确的位置 private async void RenewDataGrid_OnCellUpdated(object sender, CellUpdatedEventArgs e) { row.Cells[4].IsEnabled = false; await datacontext.Ca
private async void RenewDataGrid_OnCellUpdated(object sender, CellUpdatedEventArgs e)
{
row.Cells[4].IsEnabled = false;
await datacontext.CalculateFdtotalAmount();
row.Cells[4].IsEnabled = true;
}
我在函数调用中遇到过类似类型的XamDataGrid问题。我通过处理类似于旧windows Peek消息的语句来解决这个问题。为此,请尝试以下方法:
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);
}
谢谢你SteveFerg…我为我工作…很棒的工作…你能解释一下这背后的逻辑吗?我发现有些调用是缓存的。在退出函数之前,它实际上不会立即执行API调用。我还发现,特别是在初始窗口加载时,有时我不得不为cellpresenter呼叫设置一个短计时器。这是一个小时又一个小时的丰富多彩的语言和头部撞击的结果,以找出什么时候代码没有错,它只是不工作。我只是出于某种原因发现了一些基础设施呼叫的问题。一旦我做了上述改变,我就再也没有问题了。