Reputation: 823
I am making a search app in wp7. Every record's data is bound to a user control. I have introduced an infinite loading instead giving page numbers. So when the number of instances of the UserControl is increased in the screen the transition from one page to another page (like the preview or settings pages) or coming back from that page to the current page is getting slower. I cannot change the design (infinite loading concept).
What are the ways to handle this scenario? How about changing the visibility of the controls? And reference or suggestion will be highly appreciated.
Note I tagged WPF and Silverlight because the binding happens the same way in them, expected those to have dealt with scenarios like these.
EDIT Check this question, which is asked by me. Because of having UserControl's in the listbox the vertical offset is not being maintained. So I had no option other than using ItemsControl with scrollViewer around it. ItemsControl contains a list of 5 - 6 usercontrols which intern have itemsControls inside them, I thought virtualization may not happen in such cases. Am I right?
Upvotes: 1
Views: 399
Reputation: 39006
Take a look at this post, I believe the solution provided by Rico is what you are looking for. :)
Upvotes: 1
Reputation: 132618
In WPF, this is done by Virtualization
Using Virtualization
, only one copy (or a few copies) of the UserControl
actually gets created, and switching to another user control actually just swaps out the DataContext
that the control is bound to. It doesn't actually create a new UserControl
.
For example, if you have an VirtualizingStackPanel
with 100,000 items, and only 10 are visible at a time, it will only render about 14 items (extra items for a scroll buffer). When you scroll, the DataContext
behind those 14 controls gets changed, but the actual controls themselves will never get replaced. In contrast, a regular StackPanel
would actually render 100,000 items when it gets loaded, which would dramatically decrease the performance of your application.
This question about Virtualizing an ItemsControl can probably get you going in the right direction.
Upvotes: 2