Bind Combobox with huge data in WPF

假如想象 提交于 2019-12-12 16:21:14

问题


I am trying to bind combobox with custom object list. My object list have around 15K record and combobox takes long time to show the data after clicking on combobox.

Below are the code:

<ComboBox Height="23" Name="comboBox1" Width="120" DisplayMemberPath="EmpName" SelectedValue="EmpID" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling"/>

code behind:

List<EmployeeBE> allEmployee = new List<EmployeeBE>();
allEmployee = EmployeeBO.GetEmployeeAll();
 comboBox1.ItemsSource = allEmployee;

allEmployee have around 15K record. Can any one Suggest how can I improve my combobox performance?


回答1:


You could try a VirtualizingStackPanel as described here - http://vbcity.com/blogs/xtab/archive/2009/12/15/wpf-using-a-virtualizingstackpanel-to-improve-combobox-performance.aspx

As others have said, you really want to re-imagine your UI, as a ComboBox isn't appropriate for 15k records.




回答2:


That's bad UI design: No user will read through 15K records.

You can improve the performance by allowing the user to enter some filter criteria before showing the results, for example, by using an AutoCompleteBox instead of a ComboBox.




回答3:


Try using a VirtualizingStackPanel as ItemsPanel for the ComboBox.

<ItemsPanelTemplate x:Key="ComboBoxItemsPanelTemplate"> 
   <VirtualizingStackPanel/> 
</ItemsPanelTemplate>

<ComboBox ItemsPanel="{StaticResource ItemsTemplate}"/>


来源:https://stackoverflow.com/questions/6610601/bind-combobox-with-huge-data-in-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!