none
Bug in ComboBox when using VirtualizingStackPanel

    Question

  • Hello,

    Scrolling in a ComboBox with a VirtualizingStackPanel does not work when the items do not have the same width and an item is wider than the ComboBox.

    If for example the first item is selected and the first items have a width that's smaller than that of the ComboBox, than when an item with a large width comes into view when scrolling (using the scrollbar or using keys) the combobox scolls back to the first item. So it´s not possible to scroll to the item with a large width or the items after that one.

    Example code:

      <Grid>
        <ComboBox x:Name="cb"
                  Width="100"
                  Height="20"
                  MaxDropDownHeight="200">
          <ComboBox.ItemsPanel>
            <ItemsPanelTemplate>
              <VirtualizingStackPanel />
            </ItemsPanelTemplate>
          </ComboBox.ItemsPanel>
        </ComboBox>
      </Grid>
      for (int i = 0; i < 25; i++)
        cb.Items.Add(i.ToString());
      cb.Items.Add("Long string causing the combobox popup to become wider.");
      for (int i = 0; i < 25; i++)
        cb.Items.Add((25+i).ToString());
      cb.SelectedIndex = 0;

     
    Monday, June 21, 2010 9:41 AM

Answers

  • Hi,

    Thanks for reporting the issue. As far as I know, the issue is a known issue.

    Wednesday, June 23, 2010 3:50 AM

All replies

  • Hi,

    Thanks for reporting the issue. As far as I know, the issue is a known issue.

    Wednesday, June 23, 2010 3:50 AM
  • I've encountered this too, and entered a corresponding bug report:

    https://connect.microsoft.com/VisualStudio/feedback/details/586633/scrolling-in-a-combobox-with-a-virtualizingstackpanel-fails-when-an-item-is-wider-than-the-combobox


    Monday, August 16, 2010 12:32 PM
  • Hi,

    I bounced upon the same bug earlier today.
    This is my workaround:
    I specified a fixed width on the VirtualizingStackPanel that is large enough to hold the items.
    If you set the CanHorizontallyScroll to true, a horizontal scrollbar will appear when an item is bigger than the specified width.

    Code snippet:
    <ComboBox.ItemsPanel>
    <ItemsPanelTemplate>
    <VirtualizingStackPanel Width="250" CanHorizontallyScroll="True">
    </VirtualizingStackPanel>
    </ItemsPanelTemplate>
    </ComboBox.ItemsPanel>

    Tuesday, October 19, 2010 7:27 AM
  • any update you can offer?

    Thursday, October 27, 2011 1:46 PM