Hello,
Welcome to our Microsoft Q&A platform!
As @Barry Wang said, you can use ScrollViewer.ChangeView
with DispatcherTimer
to make ScrollViewer
scroll automatically, this is a simple example:
XAML
<ScrollViewer x:Name="TestScrollViewer">
<Rectangle Width="300" Height="3000" Fill="Gray"/>
</ScrollViewer>
XAML.cs
private DispatcherTimer _scrollTimer;
private double EveryScrollHeight = 20;
private double TotalScrollHeight = 0;
public MainPpage()
{
this.InitializeComponent();
_scrollTimer = new DispatcherTimer();
_scrollTimer.Interval = TimeSpan.FromSeconds(0.1);
_scrollTimer.Tick += ScrollTimer_Tick;
_scrollTimer.Start();
}
private void ScrollTimer_Tick(object sender, object e)
{
double scrollHeight = TestScrollViewer.ScrollableHeight;
if (scrollHeight==0)
return;
TotalScrollHeight += EveryScrollHeight;
TestScrollViewer.ChangeView(0, TotalScrollHeight, 1);
}
EveryScrollHeight
determines the height of each scroll. TotalScrollHeight
records the total scroll height. ScrollViewer.ScrollableHeight
is the remaining scrollable height of the ScrollViewer
. In the ScrollTimer_Tick
method, determine if the remaining scrollable height is 0, then stop trying to scroll.
Thanks.