Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Set dynamic height for multiple webviews in a view possible?

$
0
0

I use a customrenderer for webview, found in this forum , that reads out the height of the content and set the the webview height. The problem is, i have to use many webviews on one page, that are bind to HTML sources, so the height is all different and the customrenderer only set the height for the last webview that is rendered. All other webviews are ignored. Here is the code of the Customrenderer i use for Android. How can i set the height dynamic for all webviews?
<br /> public class ExtendWebViewRenderer : WebViewRenderer{<br /> static ExtendedWebView _xwebView = null;<br /> WebView _webView;</p> <pre><code>class ExtendedWebViewClient : Android.Webkit.WebViewClient { public override async void OnPageFinished(WebView view, string url) { if (_xwebView != null) { int i = 10; while (view.ContentHeight == 0 && i-- > 0) // wait here till content is rendered await System.Threading.Tasks.Task.Delay(10); _xwebView.HeightRequest = view.ContentHeight; } base.OnPageFinished(view, url); } } protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.WebView> e) { base.OnElementChanged(e); _xwebView = e.NewElement as ExtendedWebView; _webView = Control; if (e.OldElement == null) { _webView.SetWebViewClient(new ExtendedWebViewClient()); } } }


Viewing all articles
Browse latest Browse all 77050

Trending Articles