如何禁用 wpf 中的 xamdatagrid 单元格编辑
How to disable xamdatagrid cell editing in wpf
我使用了 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 类似的问题。我通过像旧的 windows 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);
}
我使用了 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 类似的问题。我通过像旧的 windows 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);
}