WPF Binding User Entertainment

亡梦爱人 提交于 2019-12-24 04:23:06

问题


I have ran into a situation where I have an ItemsControl generate a pretty complex visual tree from a data collection, dead simple:

<ItemsControl ItemsSource="{Binding Items}"/>

The small problem I have is when the initial binding construction occurs it can take a "noticeable" amount of time when it is building itself (anywhere from 1/2 a second to 2 seconds depending on tree complexity). During this period the UI thread is completely unresponsive (animations hang, clicks are unregistered, etc).

Virtualization is already enabled and working, so essentially all I want is the ability to play an animation while the ItemContainerGenerator does it's thing.


回答1:


Try setting most bindings to IsAsync=True:

<SomeControl SomeProperty="{Binding SomeData, IsAsync=True}"/>



回答2:


To make the UI not freeze during this, you can put the load of the Items data into a BackgroundWorker http://msdn.microsoft.com/en-us/library/cc221403(v=vs.95).aspx

Then in the end of the BackgroundWorker's method, notify that the Items property have changed.



来源:https://stackoverflow.com/questions/20638769/wpf-binding-user-entertainment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!