Skip navigation

If anyone has tried loading a large number of items into a ComboBox…you’ve probably run into a long pause as the ComboBox renders an Element for each……and…..every….object….in….your….itemssource. You might have even resorted to using a ListBox instead even though it doesn’t quite fit in your UI.

Fear not my fellow WPF’ers because I have found the solution to your pain. ComboBox derives from ItemsControl and as such, has a ItemsPanel property of type ItemsPanelTemplate.

<ItemsPanelTemplate x:Key="Template_ComboPanel">

   <VirtualizingStackPanel IsVirtualizing="True"/>

</ItemsPanelTemplate>

If you set the ItemsPanelTemplate to use a VirtualizingStackPanel, the ComboBox will virtualize and you will have a much more responsive ComboBox. Even better, setup a Style for all ComboBoxes in your app and set the ItemsPanel to be that IPT. You’ll be a much happier camper. My Combobox holding 5000 objects used to take around 5-10 seconds to show the popup. Now it pops up instantly. 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: