1

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?

Community
  • 1
  • 1
Prakash
  • 823
  • 12
  • 28

2 Answers2

2

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.

Community
  • 1
  • 1
Rachel
  • 130,264
  • 66
  • 304
  • 490
  • thanks for this information, I will check it and get back to you. I have updated my question a bit, please check if virtualization can be happened in that case. – Prakash Apr 24 '12 at 05:16
  • @Prakash `ItemsControl` does not virtualize it's items by default, however the link I have in my answer will show you how you can make it virtualized – Rachel Apr 24 '12 at 11:57
1

Take a look at this post, I believe the solution provided by Rico is what you are looking for. :)

Community
  • 1
  • 1
Justin XL
  • 38,763
  • 7
  • 88
  • 133
  • I din't exactly get how it can help this case. – Prakash Apr 25 '12 at 17:35
  • Sorry, I misunderstood your question, I thought there's only one 'add more' button... May I ask why you need one per each usercontrol? – Justin XL Apr 26 '12 at 00:27
  • each user control has a different category. Its the user's interest to load more of what he want. – Prakash Apr 26 '12 at 06:20
  • In your case you have to use a `ListBox`... I don't think a virtualized `ItemsControl` is going to work in this case. Did you try `ScrollIntoView` to scroll to the usercontrol where you clicked the 'load more' button? – Justin XL Apr 26 '12 at 07:09
  • With heavy user controls and their data, I found the scrollViewer over ItemsControl more smooth than having listbox. because list box with usercontrols like i mentioned cannot have virtualization. Check the question: http://stackoverflow.com/questions/10009982 which explains my app scenario. – Prakash Apr 26 '12 at 07:39
  • The reason that why scrollviewer with itemscontrol is smoother is because this way you disalbed data virtualization. By doing this, you will have big performance impact, like what's explained in your question. I recommand still stick with the listbox as it does virtualization automatically and this is also improved in mango (see this link http://blogs.msdn.com/b/slmperf/archive/2011/06/02/listbox-scrollviewer-performance-improvement-for-mango-and-how-it-impacts-your-existing-application.aspx); however, the downside of having vitualization turned on is, the scrolling won't be as good... – Justin XL Apr 26 '12 at 08:04