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.

复制
<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.

复制
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);


posted on 2012-09-07 14:32  GIS-MAN  阅读(362)  评论(0编辑  收藏  举报

导航