Wednesday, March 27, 2013

Windows 8: Load html in a webview control

In a Windows 8 application I added a WebView control to load some local HTML files.

I started by setting the source property of the WebView control to the HTML page I embedded into the application:

DisclaimerWebView.Source = new Uri("ms-appx-web:///assets/disclaimer.html");

But when I ran the application, I saw an empty WebView control. So I switched to the  WebView.Navigate method:

DisclaimerWebView.Navigate(new Uri("ms-appx-web:///assets/disclaimer.html"));

No effect… Bedroefde emoticon

After a while I found the reason. I had to explicitly set the Width and the Height of the WebView control. And finally my HTML was loaded.

No comments: