WPF DataGrid DataBindingComplete事件在哪里? [英] Where is WPF DataGrid DataBindingComplete event?

查看:140
本文介绍了WPF DataGrid DataBindingComplete事件在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在完成数据生成之后,我需要采取一些行动(例如,使一些单元格基于一些其他单元格可读)。在WinForm DataGridView中,我曾经在DataBindingComplete事件中做到这一点。但是,我在WPF DataGrid中找不到这样的事件。还有什么我可以使用的?

解决方案

这是我想出来的:DataContextChanged事件是正确的事件。唯一的问题是datagrid还没有准备好在我的代码里面消耗这个事件。但是,如果我使用Dispatcher.BeginInvoke,这样就可以正常工作:

  Dispatcher.BeginInvoke(DispatcherPriority.Render,new Action )=> DoSomethingWithGrid())); 

有人可以解释为什么这是必要的吗?



实际上,在处理WPF DataGrid时,我不得不在不少情况下使用Dispatcher来使其运行。为什么?


I need to take some action (e.g. make some cells readonly based on some other cells) after data biinding is completed. In WinForm DataGridView, I used to do it in DataBindingComplete event. However, I couldn't find such an event in WPF DataGrid. What else can I use?

解决方案

This is what I figured out: DataContextChanged event is the right event to use. The only problem is that the datagrid is not quite ready to be consumed in my code inside this event. However, it works fine if I use Dispatcher.BeginInvoke like this:

Dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(() => DoSomethingWithGrid()));

Can anybody explain why this is necessary?

Actually, when dealing with WPF DataGrid, I had to use Dispatcher in quite a few cases in order to make it work. Why?

这篇关于WPF DataGrid DataBindingComplete事件在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆