webview

WebView is not a Control subclass and thus does not have a control template. The display area is the Width and Height.

WebView has the characteristic that other UI regions such as controls cannot be rendered on top of the WebView. This is because of how window regions are handled internally, particularly how input events are processed and how the screen draws. If you want to render HTML content and also place other UI elements on top of that HTML content, you should use WebViewBrush as the render area. The WebView still provides the HTML source information, and you reference that WebView through element name binding and the SourceName property. WebViewBrush does not have this overlay limitation.

If you want to display an interactive WebView that only occasionally has overlapping content (such as a drop-down list or app bar), you can temporarily hide the WebView control when necessary, replacing it with an element using a WebViewBrush fill. Then, when the overlapping content is no longer present, you can display the original WebView again. For more info, see the WebView control sample.

WebView doesn’t support many of the UIElement events like KeyDown, KeyUp, and PointerPressed. A common workaround to this problem is to use WebView.InvokeScript with eval to use the HTML event handlers, and to use window.external.notify from the HTML event handler to notify the application using WebView.ScriptNotify.

Note  WebView always uses Internet Explorer 10 in document mode. Additionally, WebView does not currently support HTML5, AppCache, IndexedDB, programmatic access to the Clipboard, or geo location, and supports only the Document Object Model (DOM) properties that are supported in Metro style apps using JavaScript. Furthermore, WebView does not support the ms-appdata: scheme, although it does support the ms-appx-web: scheme. This enables you to load content files in your project.

XAML
复制
<WebView Source="ms-appx-web:///HTMLPage1.html"/>


Examples

The following code example demonstrates how to navigate a WebView to a URI contained in a TextBox named Address. The full code listing for this and the following examples is available in the WebView control sample.

C#
复制
try
{
    Uri targetUri = new Uri(Address.Text);
    WebView1.Navigate(targetUri);
}
catch (FormatException ex)
{
    // Bad address.
}


The following code example demonstrates how to load local HTML into a WebView control.

 
复制
WebView2.NavigateToString(
    "<html><body><h2>This is an HTML fragment</h2></body></html>");

The following code example demonstrates how to use a WebView control to call a JavaScript function contained in the HTML it has loaded.

 
复制
string htmlFragment = 
    "<html><head><script type='text/javascript'>function SayGoodbye() { " +
    "document.getElementById('myDiv').innerText = 'GoodBye'; } " +
    "</script></head><body><div id='myDiv'>Hello</div></body></html>";

WebView3.NavigateToString(htmlFragment);

WebView3.InvokeScript("SayGoodbye", null);


转载于:https://www.cnblogs.com/gisbeginner/articles/2675035.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值