WebView inside ScrollViewer with XAML element title

In WebView, I am loading HTML elements with WP 8.1. Whenever the content exceeds the height of the WebView, there is no problem scrolling. My problem is that I have XAML elements at the top of the WebView that should scroll along with the WebView scroll.

Source:

<ScrollViewer> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="*"/> </Grid.RowDefinitions> <Grid VerticalAlignment="Top" > <StackPanel x:name="xamlelement" Margin="15 20 0 0"> <textblock/> ------- ------- ------- </StackPanel> </Grid> <Grid x:Name="testgrid" Grid.Row="1"> <WebView Margin="0 30 0 0" x:Name="msgContent" > </WebView> </Grid> </Grid> </ScrollViewer> 

Whenever the WebView "msgContent" element scrolls, I want the "xamlelement" stack panel to scroll along with the WebView.

+8
winrt-xaml xaml
source share
2 answers

The problem here is that we can disable webview scrolling with these two steps

1) setting content in excess of html loaded in webview

2) by setting the height of the web view equal to the html content contained in it.

But then when we try to move to webview, evnets are not passed to the scrollviewer parent

+4
source share

WebView provides an InvokeScript method that executes the specified script function from the currently loaded HTML with specific arguments. When the WebView LoadCompleted event occurs, I call this JavaScript, which disables scrolling. Check all the code below.

 string DisableScrollingJs = @"function RemoveScrolling() { var styleElement = document.createElement('style'); var styleText = 'body, html { overflow: hidden; }' var headElements = document.getElementsByTagName('head'); styleElement.type = 'text/css'; if (headElements.length == 1) { headElements[0].appendChild(styleElement); } else if (document.head) { document.head.appendChild(styleElement); } if (styleElement.styleSheet) { styleElement.styleSheet.cssText = styleText; } }"; void webView_LoadCompleted(object sender, NavigationEventArgs e) { webView.InvokeScript("eval", new[] { DisableScrollingJs }); } 

From codeproject .

0
source share

All Articles