2013-07-24 173 views
1

作为Windows 8 metro应用程序的一部分,您好!我使用webview,我想禁用水平滚动,因此用户不会错误地离开信息。在Windows 8中禁用滚动和移除滚动条8 webview

我已经尝试把它放入一个scrollviewer,然后禁用水平滚动那里,但滚动条和webviewer中的滚动处于活动状态。

用户仍然能够使用,因此禁止用于它不会工作的所有输入的Web查看.. :-)

希望有人有一个简单的解决方案..

编辑:

正如评论中所写,我一直试图用JavaScript来做到不成功。

使用

.InvokeScript("eval", new string[] { "document.body.scroll = 'no';" }); 

.InvokeScript("eval", new string[] { "document.body.style.overflow ='hidden';" }); 
+0

一直在努力,看看它是否可以做期运用JavaScript和web视图期运用'webview.InvokeScript( “EVAL”,新的String [] {“document.body.style的调用脚本函数。 overflow = hidden;“});'但是引发异常.. –

+0

需要使用'隐藏',然后它会运行,只有问题是,仍然不工作。 –

+0

也尝试过'document.body.scroll ='no';'因为我读过那可能在IE中工作但仍然没有结果 –

回答

0

看起来是不可能的..

最后,我结束了使用

string html = webBrowser1.InvokeScript("eval", new string[] { "document.documentElement.outerHTML;" });

获取页面的源代码,然后使用regex.replace更改html不允许滚动,不是一个非常优雅的解决方案,不是很普遍,但为我工作。

string resultString = null; 
     try 
     { 
      resultString = Regex.Replace(html, "<YOUR REGEX HERE, RegexOptions.Singleline); 
     } 
     catch (ArgumentException ex) 
     { 
      string errorMessage1 = ex.ToString(); 
      var messageDialog = new MessageDialog(errorMessage1); 
      await messageDialog.ShowAsync(); 
     } 
0
XAML 

<Grid> 

<WebView 
Height="400" 
NavigationCompleted="theWebView_NavigationCompleted" 
x:Name="theWebView" Source="http://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!enter code here 

     SetBodyOverFlowHidden();"; 
+1

你能解释这是如何工作的吗?好的答案不仅仅需要一段代码。 – phs