1

您好,作为 Windows 8 Metro 应用程序的一部分,我使用 web 视图,并且我想禁用水平滚动,这样用户就不会错误地离开信息。

我试过把它放在一个滚动查看器中,然后在那里禁用水平滚动,但是滚动条和滚动浏览器中的滚动是活动的。

用户仍然必须能够使用网络查看器,因此禁用所有输入将不起作用.. :-)

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

编辑:

正如评论中所写,我一直在尝试使用 JavaScript 来做这件事,但没有成功。

使用

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

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

2 回答 2

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();
        }
于 2013-07-28T08:10:46.533 回答
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();";
于 2014-09-17T17:50:33.790 回答