Forum Xamarin.Forms


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Right way to implement a Xamarin Forms webview whose height adjusts dynamically based on its content

mac121mac121 Member ✭✭✭

I have implemented a Xamarin Webview control, but its height is not adjusting dynamically according to its content. I tried implementing a custom renderer suggested by @nevalenny ( and @MichaelRumpler ( The first one by @nevalenny was fine, but it is not working always, it cuts some portion of the content with incorrect height (@MichaelRumpler's ViewTreeObserver.predraw was not working for me, don't why). The important thing is that I have images also in my HTML source string. So, maybe this is causing the height to be calculated incorrectly as they are loaded. Please suggest me a working solution that works at all times, that is, webview whose height adjusts dynamically based on its content.

I also tried to evaluate javascript "document.body.offsetHeight", but I'm not able to set the returned value to webview Height. I don't know how to set webview height before webview is displayed, sometimes the problem is retrieving value from the script result when I followed @AdamPedley (

NOTE: I am not binding a URL as source for the webview, I am binding the HTML string as my webview source (using HtmlWebviewsource)

Any working solution is appreciated, thanks in advance.


Sign In or Register to comment.