Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grouping, virtualization and scrolling in a ListBox

Tags:

wpf

xaml

Using following code ListBox jumps to the next group during scrolling. Since one group shows more items than can fit screen, user never sees all items of the group. Since I have a lot of items I need viritualization.

Setting CanContentScroll="False" fixes the issue but then virtualization is gone and UI hangs for 20 seconds. Is there a way around this?

 <ListBox  
   VirtualizingStackPanel.IsVirtualizing="True"
   VirtualizingStackPanel.VirtualizationMode="Recycling"
   ScrollViewer.CanContentScroll="True">
    <ListBox.GroupStyle>
    <GroupStyle HidesIfEmpty="True">
        <GroupStyle.ContainerStyle>
        <Style TargetType="{x:Type GroupItem}">
          <Setter Property="Template">
            <Setter.Value>
              <ControlTemplate>
                <Expander IsExpanded="True">
                  <Expander.Header>
                     <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Type}"  />
                        ...
                     </StackPanel>
                  </Expander.Header>
                  <ItemsPresenter />
like image 285
Daniel Avatar asked Dec 06 '25 08:12

Daniel


1 Answers

Try using the ScrollUnit=Pixel property to get smooth scrolling. The default is ScrollUnit=Item which causes the group to scroll as one unit.

<ListBox             
         VirtualizingPanel.IsVirtualizing='True'
         VirtualizingPanel.IsVirtualizingWhenGrouping='True'
         VirtualizingPanel.ScrollUnit='Pixel'
         />
like image 54
Walt Ritscher Avatar answered Dec 07 '25 22:12

Walt Ritscher



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!