如何知道绑定何时完成?
当我将 DataGrid 上的 .ItemSource() 属性设置为 Collection 时,调用会快速返回,但实际的绑定随后发生。由于我想显示等待光标,因此我需要检测实际绑定何时完成。有这方面的活动吗?
When I set the .ItemSource() property on a DataGrid to a Collection, the call returns fast, but the actual binding happens afterwards. Since I want to display a waiting cursor, I need to detect when the actual binding has finished. Is there any event for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
任何基于 ItemsControl 的内容都使用 ItemContainerGenerator 在后台生成其项目。您可以访问 DataGrid 的 ItemContainerGenerator 属性并连接 StatusChanged 事件以确定其何时完成。如果您正在使用虚拟化和滚动,这将再次触发,因此您需要根据您的情况进行处理。
Anything based on ItemsControl uses an ItemContainerGenerator to generate its items in the background. You can access the ItemContainerGenerator property of the DataGrid and hook up the StatusChanged event to determine when it's done. If you're using virtualization and scroll, this will fire again so you need to handle that if necessary in your case.
我等待
DataGrid
的Loaded
事件触发,然后执行了BeginInvoke
,如下所示:更多详细信息可在我的答案中找到: https://stackoverflow.com/a/44464630/2101117
I waited for my
DataGrid
'sLoaded
event to fire, and I did aBeginInvoke
, like this:More details available in my answer here: https://stackoverflow.com/a/44464630/2101117
最好的选择是挂钩到窗口或用户控件中的 OnPropertyChanged 事件。每次更新属性时都会触发此事件。然后检查您想要观察的实际财产并采取行动。
Your best bet is to hook into OnPropertyChanged event in your Window or User Control. This event is fired every time a property is updated. Then check for the actual property you wish to observe and take action.