nsw

Hello All,

Quick question regarding ComboBox's that have grouping enabled. When a group is too large to display in the ComboBox expander and you use the scrollbar to move down to see the rest of the group the ComboBox will move to the next group header instead of allowing you to view the rest of the grouped items.

For example, if you grouped the items of the combobox by the first character of the display member and the group titled 'A' is too large to display, when you scroll down it will jump to the group titled 'B' rather than allow you to see the rest of the 'A' items.

Hopefully I have explained the question clearly!

The thing I am looking for is a solution to allow smooth scrolling through the items in the list rather than it jumping between the group headers.


Re: Windows Presentation Foundation (WPF) ComboBox scrolling with grouping

Wei Zhou - MSFT

Hi nsw

If you use MS Blend to see the Template of Combox, you may find the xaml similar to the following. Notice the bold code below, the CanContentScroll property is set to true, it should be false if we want the drop down items of ComboBox to scroll smoothly. We can modify the Template with MS Blend, set the CanContentScroll property to false.

Code Snippet

<Popup AllowsTransparency="true" IsOpen="{Binding Path=IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" Placement="Bottom" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Margin="1" x:Name="PART_Popup" Grid.ColumnSpan="2">

<Microsoft_Windows_Themes:SystemDropShadowChrome MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding Path=ActualWidth, ElementName=MainGrid}" x:Name="Shdw" Color="Transparent">

<Border x:Name="DropDownBorder" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1">

<ScrollViewer CanContentScroll="true">

<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.DirectionalNavigation="Contained"/>

</ScrollViewer>

</Border>

</Microsoft_Windows_Themes:SystemDropShadowChrome>

</Popup>

Best Regards

Wei Zhou






Re: Windows Presentation Foundation (WPF) ComboBox scrolling with grouping

nsw

Hello,

I gave that a try but still no joy. Below is the xaml I am using for the ComboBox:

Code Snippet

<ComboBox Name="cboCustomers" SelectedValuePath="ID" SelectionChanged="cboCustomers_SelectionChanged" ScrollViewer.CanContentScroll="False">
<ComboBox.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<Border Background="LightGray">
<TextBlock Text="{Binding Path=Name, Converter={StaticResource objFCConverter}}" />
</Border>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ComboBox.GroupStyle>
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Name}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel ScrollViewer.CanContentScroll="False"/>
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>


The staticresource objFCConverter just gets the first character of the bound name to create the group.

I added the ScrollViewer.CanContentScroll="False" properties after reading your post but they didn't fix the problem.