WPF ComboBox performance problems by binding a large collections WPF ComboBox performance problems by binding a large collections wpf wpf

WPF ComboBox performance problems by binding a large collections


According to this blog: http://vbcity.com/blogs/xtab/archive/2009/12/15/wpf-using-a-virtualizingstackpanel-to-improve-combobox-performance.aspx

I've tested it with this code:

<ComboBox Name="cbBlah" ItemsSource="{Binding}">    <ComboBox.ItemsPanel>        <ItemsPanelTemplate>            <VirtualizingStackPanel />        </ItemsPanelTemplate>    </ComboBox.ItemsPanel></ComboBox>

It works fine for first time and next times. It's not necessary to code these lines:

<VirtualizingStackPanel VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling" />

I hope this helps you.


I had the issue with slow performance as well. But I had created a class that inherited form Combobox, therefor I would like to do this programmatically. So here is that solution for other googlers out there.

ItemsPanel = new ItemsPanelTemplate();var stackPanelTemplate = new FrameworkElementFactory(typeof (VirtualizingStackPanel));ItemsPanel.VisualTree = stackPanelTemplate;


I just ran into this issue as well. I'm using this code in a custom combo box with a style template. When I ran my code in VS debugging mode the virtualization did not work properly. Once I ran it outside of debugging I can switch the content of the ObservableCollection without locking the UI up. It also might help if you set a max height and max width.

<Setter Property="ScrollViewer.CanContentScroll" Value="True"/> <Setter Property="VirtualizingStackPanel.IsVirtualizing" Value="True"/><Setter Property="VirtualizingStackPanel.VirtualizationMode" Value="Recycling"/>
<Popup>    <Border/>    <ScrollViewer>      <VirtualizingStackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained"/>    </ScrollViewer>   </Grid></Popup>