Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 310
Vinzz Avatar asked Jan 21 '23 22:01

Vinzz


2 Answers

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.

like image 99
Oren Avatar answered Jan 24 '23 11:01

Oren


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.

like image 44
AnthonyWJones Avatar answered Jan 24 '23 12:01

AnthonyWJones