问题
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