如果WebView在SeparateThread上,则[XMAL] WebView滚动问题 [英] [XMAL]WebView scroll problem if the WebView is on SeparateThread
问题描述
目前我遇到的问题是,如果我创建一个在单独的线程上运行的WebView,我只能解决这个问题。我可以像这样轻松创建它:
Currently I facing a problem which I could only solve if I create a WebView, that runs on a separate thread. I can easily create it like this:
WebView _webView = new WebView(WebViewExecutionMode.SeparateThread);
当我将这个WebView添加到UI时出现问题,我尝试将其添加到网格列中,但随后Scroll无法在WebView中运行。以下是相关代码:
The problem comes when I add this WebView to the UI, I try to add it to a column of a grid, but then the Scroll isn't working in the WebView. Here is the related code:
_webView = new WebView(WebViewExecutionMode.SeparateThread);
Grid.SetColumn(_webView, 1);
_webView.Width = 1960;
rootGrid.Children.Add(_webView);
_webView.Navigate(new Uri("http://microsoft.com"));
以下是它的XAML代码:
And here is the XAML code for it:
<ScrollViewer x:Name="rootScroll"
VerticalScrollBarVisibility="Auto" VerticalScrollMode="Auto"
HorizontalScrollBarVisibility="Auto" HorizontalScrollMode="Auto"
Margin="10"
Background="#F2F2F2">
<Grid x:Name="rootGrid"
Background="Transparent">
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="400"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Border Background="Red">
<Button Content="Go to other page"
FontSize="24"
Foreground="Black"
Click="Button_Click"/>
</Border>
</Grid>
</ScrollViewer>
Also, I uploaded a sample project about this problem. It is available
here.
推荐答案
你好IThoms91,
Hello IThoms91,
请试试这个:
<Page x:Class="WebViewTest.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:WebViewTest"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<!--<ScrollViewer x:Name="rootScroll"
VerticalScrollBarVisibility="Auto" VerticalScrollMode="Auto"
HorizontalScrollBarVisibility="Auto" HorizontalScrollMode="Auto"
Margin="10"
Background="#F2F2F2">-->
<Grid x:Name="rootGrid"
Background="Transparent">
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="400"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Border Background="Red">
<Button Content="Go to other page"
FontSize="24"
Foreground="Black"
Click="Button_Click"/>
</Border>
<WebView x:Name="inAppRoot"
Grid.Column="1"
Width="550"
ScrollViewer.HorizontalScrollBarVisibility="Visible"
ScrollViewer.HorizontalScrollMode="Enabled"
ScrollViewer.VerticalScrollBarVisibility="Visible"
ScrollViewer.VerticalScrollMode="Enabled"
Source="http://microsoft.com"
DefaultBackgroundColor="White"/>
</Grid>
<!--</ScrollViewer>-->
</Page>
删除ScrollViewer并在WebView中设置附加的ScrollViewer属性。尝试调整webview的宽度以调整滚动条。
Remove the ScrollViewer and set the attached ScrollViewer property in the WebView. Try to adjust the width of the webview to adjust the scrollbars.
有问候,
Krunal Parekh
Krunal Parekh
这篇关于如果WebView在SeparateThread上,则[XMAL] WebView滚动问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!