Click here to Skip to main content
Licence CPOL
First Posted 24 Sep 2007
Views 10,236
Downloads 363
Bookmarked 8 times

WPF Databound ComboBox Performance

By Paul D Dickinson | 24 Sep 2007
Speeding up a databound ComboBox in WPF with Templates.
2 votes, 33.3%
1
1 vote, 16.7%
2
1 vote, 16.7%
3
1 vote, 16.7%
4
1 vote, 16.7%
5
1.87/5 - 6 votes
μ 1.87, σa 2.86 [?]

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Paul D Dickinson

Software Developer
Zyto
United States United States

Member


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralThe quick way PinmemberHeinz JKarl Otta Fritz7:47 11 Jan '11  
GeneralContent is good Presentation is bad PinmemberRam Mohan Raja12:52 25 Sep '07  

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

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

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120210.1 | Last Updated 24 Sep 2007
Article Copyright 2007 by Paul D Dickinson
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid