Universal Windows App- How to disable scroll in WebView?

I ran into this problem while working with a partner. There no good solutions out there hence the blog post. We wanted to disable the scrolling in WebView in a Universal Windows 8.1 app (Windows & Windows Phone). This could be achieved by injecting a JAVA Script (  document.body.style.overflow = 'hidden';).  Working code is attached

 XAML

<Grid>

<WebView
Height="400"
NavigationCompleted="theWebView_NavigationCompleted"
x:Name="theWebView" Source="https://blogs.msdn.com/ashish"
></WebView>

 </Grid>

Code

private
async void theWebView_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs
args)

        {

            string returnStr = await
theWebView.InvokeScriptAsync("eval", new string[] {
SetBodyOverFlowHiddenString });

        }

        string SetBodyOverFlowHiddenString =
@"function SetBodyOverFlowHidden()

        {

            document.body.style.overflow =
'hidden';

            return 'Set Style to hidden';

        }

        // now call the function!

        SetBodyOverFlowHidden();";

Thanks Jeff
Sanders (https://blogs.msdn.com/b/jpsanders/)
for providing the tip   

 

 

DisableWebViewScroll.zip