Add this JavaScript to the end of your HTML which should placed in the WebBrowser-Control:
<script>
function ResizeWebBrowser() {
var _renderedHeight=document.body.firstChild.offsetHeight * 0.5;
var _json = '{""rendered_height"" : '+_renderedHeight+'}';
window.external.notify(_json);
}
ResizeWebBrowser();
</script>
On the Control, activate JavaScript and register a action for
ScriptNotify
:
<phone:WebBrowser Name="Browser" Height="100" IsScriptEnabled="True" ScriptNotify="WebBrowser_ScriptNotify" IsHitTestVisible="False" />
Now we can resize our WebBrowser-Control:
private void WebBrowser_ScriptNotify(object sender, NotifyEventArgs e)
{
Dictionary<String, String> _json = (Dictionary<String, String>)JsonConvert.DeserializeObject(e.Value, typeof(Dictionary<String, String>));
if (_json.ContainsKey("rendered_height"))
{
this.Browser.Height = Int32.Parse(_json["rendered_height"]);
}
}
That's all and it works perfectly for me. With the Option
IsHitTestVisible="False"
the WebBrowser-Control can't zoom and scroll and it feels like a Formatted
TextBlock
.