我有一个有3000个项目的组合框。扩展它需要几秒钟。有没有办法更快地扩展它?使用ItemsSource和绑定路径绑定项目:
<ComboBox ItemsSource="{Binding Path=SomeItems}" />
答案 0 :(得分:2)
您必须使用虚拟化堆栈面板来提高性能。在这种情况下,仅将ItemsPanel的ItemspanelTemplate从StackPanel更改为VirtualizingStackpanel将不会有任何魔力,因为当您按下向下按钮时,数据将加载到Popup中。所以你必须将ScrollViewer中的StackPanel修改为VirtualizingStackpanel。为此,使用Expression blend或VS编辑组合框的ControlTemplate / Style并更改控件模板弹出区域,如下所示
<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>
答案 1 :(得分:0)
<ComboBox>
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel/>
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>