1000 bindings

I have a WPF form that contains a 30x30 grid, where each grid cell is a ComboBox . The values โ€‹โ€‹of the ComboBox and the selected value are bound from the DataContext . The problem is that it is very slow. I redesigned the form so that it displays text fields instead of comboboxes (and the TextBox converts to ComboBox on mouse input), and now it works instantly.

Why is ComboBoxes so slow? Is there a way to improve the massive binding of ComboBoxes?

+4
source share
1 answer

ComboBox does not use virtualization by default ( VirtualizingStackPanel ), you can very easily change the panel used by the control:

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

Link: Combobox Performance Improvement Through UI Virtualization

This helps to significantly improve performance if the ComboBox has thousands of elements, and I'm not sure how useful it would be in your case to have 1000 lists with a list for the user interface.

You can also try placing these comboBoxes in a virtualization panel (e.g. ListBox or directly using VirtualizedStackpanel ).

Another thing you can try is to make your ComboBox ItemSource asynchronous using the IsAsync property.

Hope you are using ObservableCollection as your ItemSource ;

+5
source

All Articles