A WebView component (sub-class of View) allows you to render a piece of Html or a whole URL in an embedded browser component.
To use this component, install the Zebble.WebView nuget package.
It's open source and available on GitHub. Also we welcome any contributions to enhace it.
To show an external URL, use:
To show some html directly, use:
In the above example GetHtml() is a method in the code behind. Of course the data can come from the database, your domain objects, etc.
To show a html file from your Resources folder, use:
In the HTML page, you can reference Javascript, Image or CSS files in your Resources folder.
You can also reference web-hosted resources by specifying the full url. For example:
<script type="text/javascript" src="MyPages/MyScript.js"></script>
<script type="text/javascript" src="http://mywebsite.com/MyScript.js"></script>
...
<img src="Images/Icons/Hello.png">
The EvaluateJavascript() method allows you to run some Javascript code on the rendered page, and then get the value of its evaluation back.
- From the web page context, navigate to a psudo url, such as my-command:my-param.
- In the C# code, handle the BrowserNavigating event and get the message to process.
<a href="#my-command_param1">Foo with param1</a> <a href="#my-command_param2">Foo with param2</a> <a href="#another-command_param3">Bar with param3</a> An in the C# code:
if (e.Url.StartsWith("#my-command_")) DoMyThing(e.Url.TrimStart("#my-command_"));
else if (e.Url.StartsWith("#another-command_")) DoAnotherThing(e.Url.TrimStart("#another-command_"));
});
The Value property determines the HTML content of current page.