Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

WPF Databound ComboBox Performance

0.00/5 (No votes)
24 Sep 2007 1  
Speeding up a databound ComboBox in WPF with Templates.

Slow ComboBoxes

By following the steps in this article, you will learn how to optimize a ComboBox with WPF and Vista.

What are the Issues?

The WPF ComboBox has two main issues. First, the ComboBox uses a StackPanel, and not a VirtualizingStackPanel, in the ItemsPanelTemplate. Second, the popup overrides the defaults and sets AllowsTransparency to true.

Why does it matter?

If a StackPanel is used instead of a VirtualizingStackPanel, all of the items in the combobox must be rendered before the popup can be shown. The VirtualizingStackPanel will only render what is shown. This only matters if the items are generated through databinding and there are over 100 items.

If AllowsTransparency is set to true, every pixel is calculated to test for transparency. This causes the scrolling on Vista Home Premium and above versions to lag. It is not a problem on XP or Vista Home Basic because they do not support transparency.

How to fix it?

Create a Template for the ComboBox and set AllowsTransparency to false.

<Popup Focusable="false" AllowsTransparency="false" ...

Create a Template for the ComboBox's ItemsPanel and change the StackPanel into a VirtualizingStackPanel.

<VirtualizingStackPanel IsItemsHost="True"/>

Please let me know if this article was helpful.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here