Skip to content

Commit 70d7b0e

Browse files
committed
Fixed Task not completing issue when offset is negative
1 parent 4b70980 commit 70d7b0e

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

Microsoft.Toolkit.Uwp.UI/Extensions/ListViewBase/ListViewExtensions.SmoothScrollIntoView.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,23 @@ public static async Task SmoothScrollIntoViewWithItemAsync(this ListViewBase lis
201201
/// <param name="disableAnimation">if set to <c>true</c> disable animation.</param>
202202
private static async Task ChangeViewAsync(this ScrollViewer scrollViewer, double? horizontalOffset, double? verticalOffset, float? zoomFactor, bool disableAnimation)
203203
{
204-
horizontalOffset = horizontalOffset > scrollViewer.ScrollableWidth ? scrollViewer.ScrollableWidth : horizontalOffset;
205-
verticalOffset = verticalOffset > scrollViewer.ScrollableHeight ? scrollViewer.ScrollableHeight : verticalOffset;
204+
if (horizontalOffset > scrollViewer.ScrollableWidth)
205+
{
206+
horizontalOffset = scrollViewer.ScrollableWidth;
207+
}
208+
else if (horizontalOffset < 0)
209+
{
210+
horizontalOffset = 0;
211+
}
212+
213+
if (verticalOffset > scrollViewer.ScrollableHeight)
214+
{
215+
verticalOffset = scrollViewer.ScrollableHeight;
216+
}
217+
else if (verticalOffset < 0)
218+
{
219+
verticalOffset = 0;
220+
}
206221

207222
// MUST check this and return immediately, otherwise this async task will never complete because ViewChanged event won't get triggered
208223
if (horizontalOffset == scrollViewer.HorizontalOffset && verticalOffset == scrollViewer.VerticalOffset)

0 commit comments

Comments
 (0)