简体   繁体   English

WebBrowser 没有加载我的页面

[英]WebBrowser not loading my page

I have a WebBrowser element in my UI, I can make it navigate to a hosted page, but when I want it to load a local webpage (which is in my solution resources), which is the exact html file hosted on internet, it just shows a blank page.我的 UI 中有一个 WebBrowser 元素,我可以让它导航到托管页面,但是当我希望它加载本地网页(在我的解决方案资源中)时,这是托管在互联网上的确切 html 文件,它只是显示空白页。

browser.Navigate(new Uri("test.html", UriKind.Relative));

If I change the UriKind or the page name it shows an error that the file could not be found, so I know the browser is finding the webpage correctly but it won't render it.如果我更改 UriKind 或页面名称,它会显示找不到文件的错误,所以我知道浏览器正在正确找到网页,但它不会呈现它。

I need to do this because I want to show the page while the user is offline.我需要这样做,因为我想在用户离线时显示页面。

The browser cannot read a resource from your App/Dll.浏览器无法从您的 App/Dll 中读取资源。 However, it you have the file in the same folder as you application you could do:但是,如果您将文件放在与应用程序相同的文件夹中,则可以执行以下操作:

 var home = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
 browser.Navigate(new Uri("file://" + home + "/test.html");

If the html file has a build action of Content you can access it directly from the install location if you set a relative path.如果 html 文件具有Content的构建操作,如果您设置了相对路径,则可以直接从安装位置访问它。

If you want to be able to navigate between pages or include other resources in the file (including external css, js or even images) then you'll either need to copy all the files to IsolatedStorage and view them from there or host them externally.如果您希望能够在页面之间导航或在文件中包含其他资源(包括外部 css、js 甚至图像),那么您需要将所有文件复制到 IsolatedStorage 并从那里查看它们或在外部托管它们。

Edit:编辑:
MSDN has an article which explains copying files to IsolatedStorage, so they can be viewed in the WebBrowser control, at http://msdn.microsoft.com/en-us/library/ff431811(v=vs.92).aspx MSDN 有一篇文章解释了将文件复制到 IsolatedStorage,因此可以在 WebBrowser 控件中查看它们,网址为http://msdn.microsoft.com/en-us/library/ff431811(v=vs.92).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM