Answered by:
How to achieve a scrolling effect with ListBox.ScrollIntoView.

Question
-
Hi guys,
I am trying to achieve a scrolling effect (please see fig. below) with ListBox.ScrollIntoView.
However, instead of Scrolling Into View, the items jumped into view. 2 questions:
1, Did I miss something with ListBox.ScrollIntoView?
2. What is the proper way to achieve the scrolling effect?
Thanks.
Here is the xaml
<Window x:Class="ScrollIntoView.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <ListBox x:Name="ListBox1" ScrollViewer.HorizontalScrollBarVisibility="Hidden" HorizontalAlignment="Left" Height="30" Margin="218,140,0,0" VerticalAlignment="Top" Width="47"> <ListBox.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal"/> </ItemsPanelTemplate> </ListBox.ItemsPanel> <ListBoxItem FontSize="16">1</ListBoxItem> <ListBoxItem FontSize="16">2</ListBoxItem> <ListBoxItem FontSize="16">3</ListBoxItem> <ListBoxItem FontSize="16">4</ListBoxItem> <ListBoxItem FontSize="16">5</ListBoxItem> <ListBoxItem FontSize="16">6</ListBoxItem> <ListBoxItem FontSize="16">7</ListBoxItem> <ListBoxItem FontSize="16">8</ListBoxItem> </ListBox> <Button x:Name="Btn_MoveRight" Content="Move Right" HorizontalAlignment="Left" Height="20" Margin="275,140,0,0" VerticalAlignment="Top" Width="70" Click="Btn_MoveLeft_Click"/> <Button x:Name="Btn_MoveLeft" Content="Move Left" HorizontalAlignment="Left" Height="20" Margin="135,140,0,0" VerticalAlignment="Top" Width="70" Click="Btn_MoveRight_Click"/> </Grid> </Window>
Here is the xaml.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace ScrollIntoView { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void Btn_MoveLeft_Click(object sender, System.Windows.RoutedEventArgs e) { ListBox1.ScrollIntoView(ListBox1.Items[6]); } private void Btn_MoveRight_Click(object sender, System.Windows.RoutedEventArgs e) { ListBox1.ScrollIntoView(ListBox1.Items[0]); } } }
Monday, June 29, 2015 9:25 PM
Answers
-
Hi Richard0012,
>>”1, Did I miss something with ListBox.ScrollIntoView?”
In my opinion, you could use animation(smooth) to achieve your target. More information about “Animated (Smooth) scrolling on ScrollViewer”, you could refer to this thread for details: http://stackoverflow.com/questions/20731402/animated-smooth-scrolling-on-scrollviewer
>>”2. What is the proper way to achieve the scrolling effect?”
Please don’t post duplicate questions in the forum. I have replied in your original post, here is the link: https://social.msdn.microsoft.com/Forums/vstudio/en-US/0c97fa0a-623c-4c4e-b9b0-d40fdb3a0705/how-to-adjust-c-scrollbar?forum=wpf#1b24e5bf-8757-4e3c-b53d-6a28038bfaf6
Thank you for your understanding.
Best Regards,
Xavier Eoro
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Proposed as answer by Magnus (MM8)MVP Tuesday, June 30, 2015 1:33 PM
- Marked as answer by Xavier Xie-MSFT Monday, July 6, 2015 2:03 AM
Tuesday, June 30, 2015 5:51 AM
All replies
-
Hi Richard0012,
>>”1, Did I miss something with ListBox.ScrollIntoView?”
In my opinion, you could use animation(smooth) to achieve your target. More information about “Animated (Smooth) scrolling on ScrollViewer”, you could refer to this thread for details: http://stackoverflow.com/questions/20731402/animated-smooth-scrolling-on-scrollviewer
>>”2. What is the proper way to achieve the scrolling effect?”
Please don’t post duplicate questions in the forum. I have replied in your original post, here is the link: https://social.msdn.microsoft.com/Forums/vstudio/en-US/0c97fa0a-623c-4c4e-b9b0-d40fdb3a0705/how-to-adjust-c-scrollbar?forum=wpf#1b24e5bf-8757-4e3c-b53d-6a28038bfaf6
Thank you for your understanding.
Best Regards,
Xavier Eoro
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Proposed as answer by Magnus (MM8)MVP Tuesday, June 30, 2015 1:33 PM
- Marked as answer by Xavier Xie-MSFT Monday, July 6, 2015 2:03 AM
Tuesday, June 30, 2015 5:51 AM -
Thanks, Xavier, I will study your suggestion.
Richard
Wednesday, July 1, 2015 9:32 PM -
>>"Please don’t post duplicate questions in the forum. I have replied in your original post,"
Thanks for pay close attention to every of my questions.
I just want to see if there are other solutions, or how many solutions to it.
As you know, if a thread is marked as answered, nobody would bother to check it out again. If you like to see if there are solutions, I guess you have to start a new thread.
Thanks a again.
Have a wonderful July 4th.
Friday, July 3, 2015 8:29 PM