locked
Smooth Scrolling on ListBox RRS feed

  • Question

  •  

    I'm using a ListBox styled like a StackPanel to display data.  The data is a list of objects, so each ListBoxItem is bound to an item.  Some ListBoxItems are very tall, others very short.

     

    The ListBox scrolls an entire item at once.  There is no smooth scrolling.  So when a single ListBoxItem is taller than the height of the ListBox, I cannot read the entire item.  Scroll snaps to the next item.

     

    I've placed a ScrollViewer around the ListBox to achieve smooth scrolling, but now clicking on a ListBox item that doesn't appear at the top is impossible.  For example, when I scroll to the last item and click on it, the ListBox jumps back to the top.

     

    Any ideas?

    Tuesday, March 25, 2008 3:11 PM

Answers

  • Have you tried setting :

    ScrollViewer.CanContentScroll="False" on the list box?

     

    This way the scrolling is handled by the panel rather than the listBox... You lose virtualisation if you do that though so it could be slower if you have a lot of content.

    Tuesday, March 25, 2008 4:11 PM

All replies

  • Have you tried setting :

    ScrollViewer.CanContentScroll="False" on the list box?

     

    This way the scrolling is handled by the panel rather than the listBox... You lose virtualisation if you do that though so it could be slower if you have a lot of content.

    Tuesday, March 25, 2008 4:11 PM
  •  

    Not a lot of content.

     

    That works great!  Thanks.

    Brian

    Tuesday, March 25, 2008 6:44 PM
  • I was facing the same issue and set ScrollViewer.CanContentScroll="False" but somehow my vertical scrollbar is getting disabled after setting CanContentScroll to false. Any idea?
    Friday, February 26, 2010 9:19 AM
  • Thanks a lot! you resolved my issues too.
    Tuesday, November 29, 2011 10:20 AM
  • This is how I established smooth scrolling using the ScrollViewer:

    <ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Auto" DockPanel.Dock="Left">
    	<ListBox 
    		Name="WritingsReferenceListBox"
    		IsSynchronizedWithCurrentItem="true"
    		HorizontalContentAlignment="Stretch"
    		ScrollViewer.IsDeferredScrollingEnabled="True"
    		VirtualizingStackPanel.IsVirtualizing="True"
    		ItemTemplate="{Binding Source={StaticResource WritingsReferenceTemplate}}"
    		ItemsSource="{Binding XPath=./WritingsReference}"
    		SelectedIndex="0">
    		<ListBox.Template>
    			<ControlTemplate TargetType="ListBox">
    				<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderBrush}">
    					<ItemsPresenter/>
    				</Border>
    			</ControlTemplate>
    		</ListBox.Template>
    	</ListBox>
    </ScrollViewer>

    Got the some of my idea from here How can make ScrollViewer scroll when mouse is over *any* content


    Code is like a box of chocolates!...


    • Edited by VcDeveloper Thursday, September 26, 2013 4:14 AM added source
    Thursday, September 26, 2013 4:08 AM