0

I have a list of items inside windows 8.1 listview what I wanted to do is, on a button click I like to auto scroll the items inside list view.

I was able to achieve this if I add those items inside stackpanel and wrapped it within scrollviewer control. But I was unable to animate the inbuilt scrollviewer of the listview.

So Is it possible to animate listview / gridview's default scrollviewer using storyboard in W8.1 store app.

<ListView x:Name="OnboardPanel" HorizontalAlignment="Stretch" ScrollViewer.VerticalScrollBarVisibility="Hidden">
            <ListView>
                <ItemsPanelTemplate>
                    <ItemsWrapGrid x:Name="OnboardWrapGrid" MaximumRowsOrColumns="6" Orientation="Horizontal" HorizontalAlignment="Stretch" Background="Red"/>
                </ItemsPanelTemplate>
            </ListView>
            <ListView>
                <DataTemplate>
                    <Image Source="{Binding ImageName}" Margin="1" Stretch="UniformToFill"/>
                </DataTemplate>
            </ListView>
        </ListView>



private void Button_Click(object sender, RoutedEventArgs e)
        {
            //myStoryboard.Begin();
            Storyboard storyboard1 = new Storyboard();
            DoubleAnimation verticalScrollOffsetAnimation = new DoubleAnimation
            {
                From = 0,
                To = 1000,
                Duration = new TimeSpan(0, 0, 0, 3, 0),
                EnableDependentAnimation = true
            };

            storyboard1.Children.Add(verticalScrollOffsetAnimation);
            Storyboard.SetTarget(verticalScrollOffsetAnimation, OnboardPanel.GetScrollViewer());
            Storyboard.SetTargetProperty(verticalScrollOffsetAnimation, "VerticalOffset");
            //storyboard1.FillBehavior = FillBehavior.Stop;
            //storyboard1.RepeatBehavior = RepeatBehavior.Forever;
            storyboard1.Begin();
        }
Jeevaraj
  • 1
  • 1
  • listview has scrollintoview method, have you tried that? – Chirag Shah Feb 29 '16 at 10:43
  • I don't want to use this method. I have to animate scrolling for more than 3 minutes or so (I mean I have to scroll it very very slow). If I use this method then it will scroll with in a second. But if I use storyboard animation then I can animate scrolling for any time given period. – Jeevaraj Feb 29 '16 at 10:57
  • possible duplicate of (http://stackoverflow.com/questions/26198000/animate-smoothly-scrollviewer-programatically) ? – Chirag Shah Feb 29 '16 at 11:25
  • Thank you so much Chirag Shah. I used your reference as a sample and did some code to animate the scrollviewer within listview. Its working!!! – Jeevaraj Mar 01 '16 at 10:11

1 Answers1

0

I used below as a sample and did some code changes to add storyboard animation to animate scrollviewer in listview.

Animate (smoothly) ScrollViewer programmatically

Community
  • 1
  • 1
Jeevaraj
  • 1
  • 1