wpf solution

In my previous post i talked about running into a WPF performance problem. I had several thousand controls that i added to a stackpanel. the choke point was the stackpanel.children.add function.

Adding 10,000 items was taking around about 10 seconds to run. 8.5 seconds was spent on the stackpanel.children.add. around 1.5 seconds was spent on creating the controls.

To fix the problem I have used a variation on the WPF virtualizingstackpanel. The theory behind virtualizing stackpanels is that the stackpanel only initialises and displays the items that are actually on screen. When the stackpanel has to show new gui elements, it creates the new elements and distroys any that are no longer on screen.

The 2 engineering problems this brings up are 1- how to work out what is on screen and 2 how to store all the objects that may be potentially turned into gui elements.

For my project, i have a tv guide that has 100's of tv stations and each one needs 1 weeks worth of guide data.

To store the data i have essentially made a big 2d array.

When the user scrolls the guide, new gui elements are created on the fly and added to the stackpanel.

The resulting code now takes less than 100 milliseconds to load up rather than 10 seconds.

So that gives a speed up of around 100 times.

0 comments: