如何知道绑定何时完成?

发布于 2024-12-16 01:32:57 字数 111 浏览 5 评论 0原文

当我将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

谁的年少不轻狂 2024-12-23 01:32:57

任何基于 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.

箜明 2024-12-23 01:32:57

我等待 DataGridLoaded 事件触发,然后执行了 BeginInvoke,如下所示:

private void SubjectsList_Loaded(object sender, RoutedEventArgs e)
{
    Dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(() => ColorMyRows()));
}

更多详细信息可在我的答案中找到: https://stackoverflow.com/a/44464630/2101117

I waited for my DataGrid's Loaded event to fire, and I did a BeginInvoke, like this:

private void SubjectsList_Loaded(object sender, RoutedEventArgs e)
{
    Dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(() => ColorMyRows()));
}

More details available in my answer here: https://stackoverflow.com/a/44464630/2101117

自控 2024-12-23 01:32:57

最好的选择是挂钩到窗口或用户控件中的 OnPropertyChanged 事件。每次更新属性时都会触发此事件。然后检查您想要观察的实际财产并采取行动。

    protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
    {
        if ("YOUR_PROPERTY_NAME".Equals(e.Property.ToString()))
        {
            // Take action
        }
        base.OnPropertyChanged(e);
    }

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.

    protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
    {
        if ("YOUR_PROPERTY_NAME".Equals(e.Property.ToString()))
        {
            // Take action
        }
        base.OnPropertyChanged(e);
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文