Tips and tricks : Silverlight autocompletebox with huge amount of data

Tips and tricks : Silverlight autocompletebox with huge amount of data

This new post will explain the ability to use the autocomplete box with more than 10 000 items in the list. It will result an unpleasant latency… It will freeze your user interface during seconds !

The silverlight solution

You just need to add the System.Windows.Control reference.

The main page Xaml is like described below :

Generate items

Here is the little code that generate 12 000 lines and put it to the itemsource :

You can run the sample at this time. There is a 10 sec latency (dependant to your computer power)…

Solve the problem

We will use blend to speed up development and show the simplest way to produce this solution.
At this time you need to edit the general template (Edit a copy, not create a blank one) :

 
And edit the “ItemPanel” of your selector :

 
You must replace the “StackPanel” with a VirtualizingStackPanel:
 –> 
At this point you mzy think you have finished but, if you run your solution, you will see it remains the latency.

Final tips

The tricky trick is to add a MaxHeight that force the system to generate a maximum of 250px of ItemTemplate

 

Sources

Sources are available here
 
 

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *