如何提高 Silverlight 绑定性能?
场景:
我有许多(可能有几十个)ObservableCollection 在加载时绑定到 ListBox。这些绑定在各自的 Xaml 文件中声明。当应用程序首次运行时,它会查询数据库,然后填充这些 ObservableCollections(通过将新实体添加到各自的集合中)。
我怀疑向数据绑定的 ObservableCollection 添加元素是一个性能问题。
副作用是,当应用程序最初运行时,会出现一些问题(UI 短暂冻结)。我想尽可能多地消除这些问题。
任何见解、陷阱和技巧等都非常适用。提前致谢!
Scenario:
I have many (potentially dozens) of ObservableCollection's being bound to ListBoxes at load time. These bindings are declared in their respective Xaml files. When the app first runs, it queries a database and then populates these ObservableCollections (by adding a new entity to their respective collection).
I suspect that the fact that im adding elements to a data-binded ObservableCollection is a performance concern.
The side effect is that when the app initially runs, there are hiccups (brief moments of UI-freezes). I would like to eliminate as much of these hiccups as possible.
Any insights and gotchas and tips...etc are much appricated. Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里有一些提示:
如果在数据初始加载之后才进行数据绑定,速度会更快。
如果在加载数据之前不使绑定的 UI 元素可见,则速度应该会更快。
如果您在对象 DependencyProperties 上设置绑定源属性,可能会更快。
Here are a few tips:
If you don't do the data binding until after the data is initially loaded, it will be faster.
If you don't make the bound UI elements visible until the data is loaded, it should be faster.
If you make the binding source properties on your objects DependencyProperties, it might be faster.
确保不使用双向数据绑定。如果列表中的数据在客户端应用程序的生命周期内是静态的,您甚至可以考虑单向一次性观察。
Make sure you don't use two-way data binding. If the data in the lists is static over the lifetime of the app on the client, you can even consider one-time obver one-way.