我有一個3000個項目的組合框。它需要幾秒鐘才能展開。有沒有辦法更快地擴展它?該項目採用的ItemsSource和綁定路徑約束:增強combobox擴展速度
<ComboBox ItemsSource="{Binding Path=SomeItems}" />
我有一個3000個項目的組合框。它需要幾秒鐘才能展開。有沒有辦法更快地擴展它?該項目採用的ItemsSource和綁定路徑約束:增強combobox擴展速度
<ComboBox ItemsSource="{Binding Path=SomeItems}" />
<ComboBox>
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel/>
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>
你必須使用虛擬化的StackPanel以提高性能。在這種情況下,只需將ItemsPanel的ItemspanelTemplate從StackPanel更改爲VirtualizingStackpanel就不會有什麼魔力,因爲當您按下按鈕時,數據將加載到Popup中。所以你必須將ScrollViewer中的StackPanel修改爲VirtualizingStackpanel。要做到這一點編輯使用Expression Blend中或VS,改變像下面
<Popup
Name="Popup"
Placement="Bottom"
IsOpen="{TemplateBinding IsDropDownOpen}"
AllowsTransparency="True"
Focusable="False"
PopupAnimation="Slide">
<Grid
Name="DropDown"
MinWidth="{TemplateBinding ActualWidth}"
MaxHeight="{TemplateBinding MaxDropDownHeight}">
<Border
x:Name="DropDownBorder"
Background="{StaticResource WindowBackgroundBrush}"
BorderThickness="1"
BorderBrush="{StaticResource SolidBorderBrush}"/>
<ScrollViewer Margin="4,6,4,6">
<VirtualizingStackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" />
</ScrollViewer>
</Grid> </Popup>
謝謝你的回答,但它是一個矯枉過正的:) – 2011-12-26 16:48:44
控制模板彈出區域的組合框控件模板/樣式這裏是爲[UI虛擬化(HTTP一些組合框代碼:// BEA。 stollnitz.com/blog/?p=338) – 2011-12-16 15:10:22