开发者

Silverlight combobox performance issue

I'm facing a performance issue with a crowded combobox (5000 items). Rendering of the drop down list is really slow (as if it was computing all items before showing any).

Do you have any trick to make this dropdown display lazy?

Xaml code:

  <Grid x:Name="LayoutRoot">
        <StackPanel Orientation="Horizontal" Width="200" Height="20">
            <TextBlock>Test Combo </TextBlock>
            <ComboBox x:Name="fooCombo" Margin="5,0,0,0"></ComboBox>
        </StackPanel>
    </Grid>

code behind:

public MainPage() { InitializeComponent();

    List<string> li = new List<string>();

    int Max = 5000;
    for (int i = 0; i < Max; ++i)
        li.Add("Item - " + i);

    fooCombo.ItemsSource = li;
}

Well, there seems to be a bug in the Combobo开发者_高级运维x UI virtualization, so an autocompletebox should be the way to go.


If you want an actual ComboBox (and not an AutoCompleteBox) that did this you could replace the ItemsTemplate with a VirtualizingStackPanel. In your example this would look like:

<ComboBox x:Name="fooCombo" Margin="5,0,0,0">
    <ComboBox.ItemsPanel>
        <ItemsPanelTemplate>
            <VirtualizingStackPanel></VirtualizingStackPanel>
        </ItemsPanelTemplate>
    </ComboBox.ItemsPanel>
</ComboBox>

As a guide though, I'd probably review your usage scenario to see whether or not a ComboBox is the correct control for you - since 5000 items seems like a mighty lot for a drop down list.

By the way, the slowness is expected behavior in Silverlight and not a bug.


Use the AutoCompleteBox instead, adjust the number of characters that need to be entered before a drop down list will be filled to limit how many drop down items are needed at any one time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜