Skip to content

Instantly share code, notes, and snippets.

@mvacha
Created May 2, 2016 17:16
Show Gist options
  • Save mvacha/0edada76223df288716007ed9a508870 to your computer and use it in GitHub Desktop.
Save mvacha/0edada76223df288716007ed9a508870 to your computer and use it in GitHub Desktop.
public static async Task ChangeViewAsync(this ScrollViewer scrollViewer, double? horizontalOffset, double? verticalOffset, bool disableAnimation)
{
var tcs = new TaskCompletionSource<object>();
EventHandler<ScrollViewerViewChangedEventArgs> viewChanged = (s, e) => tcs.TrySetResult(null);
try
{
scrollViewer.ViewChanged += viewChanged;
scrollViewer.ChangeView(horizontalOffset, verticalOffset, null, disableAnimation);
await tcs.Task;
}
finally
{
scrollViewer.ViewChanged -= viewChanged;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment