Click here to Skip to main content
15,885,748 members
Articles / Desktop Programming / WPF

WPF Databound ComboBox Performance

Rate me:
Please Sign up or sign in to vote.
1.87/5 (6 votes)
24 Sep 2007CPOL1 min read 33.2K   1.3K   8   3
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.

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

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

XML
<VirtualizingStackPanel IsItemsHost="True"/>

Please let me know if this article was helpful.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Zyto
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionThank you Pin
ITGuy32721-Jun-12 4:25
ITGuy32721-Jun-12 4:25 
GeneralThe quick way Pin
Yet another user11-Jan-11 6:47
Yet another user11-Jan-11 6:47 
GeneralContent is good Presentation is bad Pin
Rammohan Raja25-Sep-07 11:52
Rammohan Raja25-Sep-07 11:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.