2013-07-24 82 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