如何删除双滚动。在xaml uwp中的ScrollViewer中的WebView

时间:2017-05-17 08:18:04

标签: xaml webview uwp scrollview

我尝试在uwp中创建页面。我想要女巫一些元素和WebView。如何避免双滚动(一个在整个ScrollViewer上,第二个在WebView上)?我想只在ScrollViewer上滚动。

enter image description here

我的xaml代码

    <ScrollViewer>

            <StackPanel Name="NewsInformation" Margin="5,0,5,0">
                <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Height="Auto">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="150" />
                        <RowDefinition Height="auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>


                    <Image Source="{Binding Image,Converter={StaticResource ImageShow}}" Grid.Row="0" Stretch="UniformToFill" />
                    <!--<Canvas Canvas.ZIndex="1000" Grid.Row="0">-->
                    <!--<TextBlock Text="{Binding Title}" VerticalAlignment="bottom" TextWrapping="Wrap"  Foreground="red" />-->
                    <StackPanel Grid.Row="0" VerticalAlignment="bottom" Background="#cc000000" Padding="10">
                        <TextBlock Text="{Binding SneakPeak}" TextWrapping="Wrap"  MaxLines="2" FontSize="15" Foreground="#ffffff" />
                    </StackPanel>
                    <!--</Canvas>-->
                    <StackPanel Orientation="Horizontal" VerticalAlignment="Top" Grid.Row="1" Margin="10, 10, 10, 5">
                        <TextBlock Text="{Binding CreationDate}" Foreground="#595959" TextWrapping="Wrap" FontSize="7"/>
                        <TextBlock Text="|" Margin="5,0,5,0" Foreground="#595959" FontSize="7"/>
                        <TextBlock Text="{Binding Author.Name}" Foreground="#595959" FontSize="7"/>
                        <TextBlock Text="{Binding Author.Surname}" Foreground="#595959" Margin="3,0,0,0" FontSize="7"/>
                    </StackPanel>
                    <StackPanel Orientation="Vertical" VerticalAlignment="Top" Grid.Row="2" Margin="10, 0, 10, 20">
                        <TextBlock Text="{Binding Title}" HorizontalAlignment="Stretch" FontSize="12" TextWrapping="Wrap" Margin="0, 0, 0, 10" VerticalAlignment="Top" FontWeight="Bold"/>
                        <!--<TextBlock Text="{Binding Content}" HorizontalAlignment="Stretch"  TextWrapping="Wrap" VerticalAlignment="Top"  FontSize="10"/>-->
                        <WebView x:Name="newsContent" Height="400"  HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
                    </StackPanel>
                </Grid>
        </StackPanel>
    </ScrollViewer>

我希望从WebView显示所有html,并在所有页面上都有一个滚动。

1 个答案:

答案 0 :(得分:1)

这不能在XAML中完成。 您可以通过修改HTML内容本身来实现。例如,您可以通过在HTML页面中声明以下正文来删除垂直滚动条:

<body style="overflow-y: hidden">....</body>

您也可以在加载页面后注入脚本以禁用滚动条。

myWebView.NavigateToString("<html><body>my very long content</body></html>");
myWebView.LoadCompleted += async (s, args) => await myWebView.InvokeScriptAsync("eval", new string[] { "document.body.style.overflowY='hidden'" });