WPF 绑定:限制绑定列表的更新 [英] WPF Binding: Throttle the binding list's updates

查看:43
本文介绍了WPF 绑定:限制绑定列表的更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 xamdatagrid 绑定到一个列表.但是由于列表 GUI 上的更新太多,因此卡住了.如何停止这些更新并在间隔(例如 500 毫秒)后刷新网格.将响应式扩展的节流方法有用吗?

I am binding the xamdatagrid to a list.But since there are too many updates on the list GUI get stuck.How can I stop these updates and refresh the grid after an interval(say 500 ms).Will Reactive extension's throttle method be useful?

推荐答案

您可以使用 DeferRefresh 推迟绑定更新,直到您完成对集合的修改:

You can use the DeferRefresh to defer the binding update until you're done making modifications to the collection:

using (collection.DeferRefresh())
{
    // Make changes to the collection
    ...
}

如果集合是实时更新的,你可以使用一个定时器来每隔一段时间更新绑定:

If the collection is being updated in real time, you could use a timer to update the binding at intervals:

private IDisposable _deferral;
private void refreshTimer_Tick(object sender, EventArgs e)
{
    if (_deferral != null)
        _deferral.Dispose();

    _deferral = collection.DeferRefresh();
}

这篇关于WPF 绑定:限制绑定列表的更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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