【问题标题】:How to disable xamdatagrid cell editing in wpf如何在 wpf 中禁用 xamdatagrid 单元格编辑
【发布时间】:2015-09-29 04:33:34
【问题描述】:

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

【问题讨论】:

    标签: c# wpf mvvm infragistics


    【解决方案1】:

    我在函数调用中遇到过与 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);
        }
    

    【讨论】:

    • 谢谢你 SteveFerg...我为我工作...很棒的工作...你能解释一下这背后的逻辑吗?
    • 我发现有些调用被缓存了。在您退出函数之前,它实际上不会立即执行 API 调用。我还发现,尤其是在初始窗口加载时,有时我不得不为 cellpresenter 调用设置一个短计时器。这是数小时的丰富多彩的语言和头疼的结果,以找出代码什么时候没有问题,它就是行不通的。由于某种原因,我只发现某些 Infragistics 调用的问题。完成上述更改后,我就再也没有遇到过问题。
    猜你喜欢
    • 2011-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-04
    • 1970-01-01
    • 2020-10-28
    • 1970-01-01
    相关资源
    最近更新 更多