title: How to disable Webview scrolling and set it's height to fit the entire content
body: <p>I am using webview to show and edit the content in my UWP application. I want to disable the scrolling within the Webview control and make it adapt the height just to fit the entire content it has. And then it should respect the scrolling of it's parent control's scrollviewer. I have uploaded a sample application on OneDrive here: <a href="https://1drv.ms/u/s!AhChIerZubKRjQKBH5nA0KGTtPYP" rel="nofollow">https://1drv.ms/u/s!AhChIerZubKRjQKBH5nA0KGTtPYP</a></p>
  
  <p>In the sample app, you can see that once you reach at the end of the scrollviewer, the webview will start scrolling within itself. Instead what I would like to do is, keep scrolling (the parent scrollviewr) to the end of the webview.</p>
  
  <p>Edit: Here's the code:</p>
  
  <p>MainPage.xaml:</p>
  
  <pre><code>&lt;ScrollViewer VerticalScrollBarVisibility="Auto" VerticalScrollMode="Auto" Height="200" Width="400"&gt;
          &lt;StackPanel&gt;
              &lt;Button Content="Navigate web page 1"
                      Margin="0,20,0,0"
                      HorizontalAlignment="Center"
                      Click="Button_Click"/&gt;
  
              &lt;Button Content="Navigate web page 2"
                      Margin="0,20,0,0"
                      HorizontalAlignment="Center"
                      Click="Button_Click_1"/&gt;
  
              &lt;Button Content="Navigate web page 3"
                      Margin="0,20,0,0"
                      HorizontalAlignment="Center"
                      Click="Button_Click_2"/&gt;
  
              &lt;Button Content="Navigate web page 4"
                      Margin="0,20,0,0"
                      HorizontalAlignment="Center"
                      Click="Button_Click_3"/&gt;
              &lt;WebView Name="WebView" Width="400" MinHeight="200"&gt;&lt;/WebView&gt;
          &lt;/StackPanel&gt;
  &lt;/ScrollViewer&gt;
  </code></pre>
  
  <p>MainPage.xaml.cs:</p>
  
  <pre><code>public sealed partial class MainPage : Page
      {
          private const string EditableParameter = "~editable~";
          private const string SetBodyEditableScript = @"
                  try
                  {  
                          document.body.contentEditable = '" + EditableParameter + @"';
                  }
                  catch(e)
                  {
  
                  }";
  
          private const string SetTextFromClipBoardFunctionName = "setTextFromClipBoard";
          private const string SetHtmlTextFromClipboardFunction =
                  "function " + SetTextFromClipBoardFunctionName + @"(htmlFromClipboard) 
                  {
                     if (window.getSelection) 
                      {       
                          var range;
                          var sel  = window.getSelection();
                          if (sel.rangeCount) {
                              range = sel.getRangeAt(0);
                              range.deleteContents();
  
                              var el = document.createElement('div');
                              el.innerHTML = htmlFromClipboard + '&lt;span&gt;&lt;/span&gt;';
                              var frag = document.createDocumentFragment(), node, lastNode;
                              while ( (node = el.firstChild) ) {
                                  lastNode = frag.appendChild(node);
                              }
                              range.insertNode(frag);
                              range.collapse(false); 
                              window.external.notify('RefreshAndReportHtml');
                        }
                          else if (typeof document.selection != 'undefined' &amp;&amp; document.selection.type != 'Control') {
                                  var html = (node.nodeType == 1) ? node.outerHTML : node.data;
                                  html += '&lt;span&gt;&lt;/span&gt;';
                                  var textRange = document.selection.createRange();
                                  textRange.pasteHTML(html);
                                  textRange.collapse(false);
                                  window.external.notify('RefreshAndReportHtml');
                        }
                      }     
                  };";
  
          private const string GetHtmlFunctionName = "getHtml";
          private const string GetHtmlFunction =
                  "function " + GetHtmlFunctionName + @"(skipParam) 
                  {
                      return document.documentElement.innerHTML;
                  };";
  
          public MainPage()
          {
              this.InitializeComponent();
              MakeWebviewEditable();
              this.NavigationCacheMode = NavigationCacheMode.Required;
          }
  
          private void Button_Click(object sender, RoutedEventArgs e)
          {
              //(Window.Current.Content as Frame).Navigate(typeof(WebviewPage), "http://tsn.ua");
          }
  
          private void Button_Click_1(object sender, RoutedEventArgs e)
          {
              //(Window.Current.Content as Frame).Navigate(typeof(WebviewPage), "http://buzzfeed.com");
          }
  
          private void Button_Click_2(object sender, RoutedEventArgs e)
          {
              //(Window.Current.Content as Frame).Navigate(typeof(WebviewPage), "http://microsoft.com");
          }
  
          private void Button_Click_3(object sender, RoutedEventArgs e)
          {
              //(Window.Current.Content as Frame).Navigate(typeof(WebviewPage), "http://cnn.com");
          }
  
          private const string EventNotificationFormat = @"window.external.notify('{0}');";
          private async void MakeWebviewEditable()
          {
              WebView.NavigateToString("I do not know how that about righting wrongs can be, said the bachelor, for from 707" +
                                      "straight you have made me crooked, leaving me with a broken leg that will never see itself straight again all the days of its life and the injury you have redressed in my case" +
                                      "has been to leave me injured in such a way that I shall remain injured for ever and the height of misadventure it was to fall in with you who go in search of adventures." +
                                      "I do not know how that about righting wrongs can be, said the bachelor, for from 707" +
                                      "straight you have made me crooked, leaving me with a broken leg that will never see itself straight again all the days of its life and the injury you have redressed in my case" +
                                      "has been to leave me injured in such a way that I shall remain injured for ever and the height of misadventure it was to fall in with you who go in search of adventures.");
              //await InjectJavaScriptAsync(SetBodyEditableScript.Replace(EditableParameter, "true"));
              await InjectJavaScriptAsync("document.designMode='on'");
              await InjectJavaScriptAsync(GetHtmlFunction);
          }
  
          private async Task InjectJavaScriptAsync(string jscript)
          {
              await WebView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =&gt;
              {
                  try
                  {
                      // Only execute JS if a document is fully loaded. This should eliminate JS exception related to UNKNOWN name errors.
                      //if (IsHtmlLoaded)
                      string result = await WebView.InvokeScriptAsync("eval", new string[] { jscript });
                  }
                  catch (Exception ex)
                  {
  
                  }
              });
          }
      }
  </code></pre>
  
  <p>Can it be done?</p>