views:

135

answers:

2

Hi,

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 Combobox UI virtualization, so an autocompletebox should be the way to go.

+1  A: 

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.

AnthonyWJones
that's indeed a workaround, I'll consider this.
Vinzz
@Vinzz: Not sure if there is a true solution (if this is just a work around) since the requirement to fill a combobox with 100s let alone 1000s of items is a not a very good UI design decision in the first place.
AnthonyWJones
+2  A: 

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.

Oren