gpt4 book ai didi

c# - 如何在WPF中禁用XamDataGrid单元格编辑

转载 作者:行者123 更新时间:2023-12-03 10:35:17 25 4
gpt4 key购买 nike

我使用了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);
}

关于c# - 如何在WPF中禁用XamDataGrid单元格编辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32835743/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com