2

I used to have a scroll viewer for terms and conditions, when the user scrolled to the bottom I made the accept button active so they could only proceed once they scrolled.

I used to catch the scroll to bottom event using this code:

scrollViewerMain.ViewChanged += ScrollViewerMain_ViewChanged;

and

private void ScrollViewerMain_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
{
    if (_scrolledToBottomEventHandlerHit)
    {
        return;
    }

    var verticalOffsetValue = scrollViewerMain.VerticalOffset;
    var maxVerticalOffsetValue = scrollViewerMain.ExtentHeight - scrollViewerMain.ViewportHeight;

    if (maxVerticalOffsetValue < 0 || verticalOffsetValue == maxVerticalOffsetValue)
    {
        _scrolledToBottomEventHandlerHit = true;
        // Scrolled to bottom - trigger event
        ScrolledToBottom(this, new EventArgs());
    }
}

This was working fine, but now the terms and conditions come as html, so I have to use the WebView control so the formatting is correct. There isn't a ViewChanged event - so how can I achieve the same result - when the user scrolls to the bottom of the WebView, the button is enabled?

Percy
  • 2,855
  • 2
  • 33
  • 56
  • I dont think you can get end of the scroll event. You have to do it by invoking the Javacsript. If you dont have any user interactions in webview there is a work arround – Archana Mar 07 '17 at 12:36

1 Answers1

0

The WebView's scroll bar is not accessible to the app directly, because it is a part of the embedded Edge browser view. You can however solve your problem using WebView.InvokeScriptAsync method, where you can invoke a script, that will check for the time when the user reached the end of the page.

await web.InvokeScriptAsync("eval", new string[] { script });

Such scripts can be found for example here.

To actually notify your C# code, when the user scrolls down to the bottom, you will also need to inject a web allowed object. A great tutorial for that is available here on Martin Suchan's blog. You can use this injected object to notify back your C# code about the event and then enable the button in that method.

Community
  • 1
  • 1
Martin Zikmund
  • 38,440
  • 7
  • 70
  • 91