C# WebView.Navigate仅显示白色屏幕

C# WebView.Navigate仅显示白色屏幕,c#,webview,uwp,windows-runtime,windows-phone-8.1,C#,Webview,Uwp,Windows Runtime,Windows Phone 8.1,WebView.Navigate(URI)不会加载我的URI指向的html文件。 PathToIndex来自StorageFile.Path private static readonly Uri HomeUri = new Uri("ms-appx-web:///" + PathToIndex, UriKind.Absolute); 我要加载的html来自我以前解压缩过的Zip文件 有什么建议吗 编辑Jogy的答案: 这里是我解压缩zip文件的地方: var localFolder = Wi

WebView.Navigate(URI)不会加载我的URI指向的html文件。 PathToIndex来自
StorageFile.Path

private static readonly Uri HomeUri = new Uri("ms-appx-web:///" + PathToIndex, UriKind.Absolute);
我要加载的html来自我以前解压缩过的Zip文件
有什么建议吗

编辑Jogy的答案: 这里是我解压缩zip文件的地方:

var localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
var unpackFolder = await localFolder.CreateFolderAsync(appName+"unzip", CreationCollisionOption.ReplaceExisting);
然后我用
StorageFile.Path
保存index.html路径
我尝试了ms appdata,但我得到的
值不在预期范围内
异常
我可以使用

var files = await unpackFolder.GetFilesAsync();
foreach(var file in files)
{
   string name = file.Path;
}


使用NavigateToString,我也可以看到Html文件,但javascript和css仍然无法工作。ms appx web无法工作,因为它只能用于从应用程序包加载资源

我尝试了ms appdata,然后搜索了,结果发现:

WebView不支持ms appdata方案,尽管它支持 支持ms appx web方案,您可以使用该方案加载内容 应用程序包中的文件

解决方法是读取字符串中的文件内容,然后使用WebView.NavigateToString()。 如果您有html的外部资源,还可以浏览NavigateToLocalStreamUri()。

这将帮助您。。。

我的例子是:

StorageFolder d = await ApplicationData.Current.LocalFolder.CreateFolderAsync("folder", CreationCollisionOption.OpenIfExists);
StorageFile f = await d.CreateFileAsync("index.html", CreationCollisionOption.ReplaceExisting);
Stream str = await f.OpenStreamForWriteAsync();
using (StreamWriter sw = new StreamWriter(str))
{
  sw.Write("<html>...</html>");
}
string url = "ms-appdata:///local/folder/index.html";
webView1.Navigate(new Uri(url));
StorageFolder d=wait ApplicationData.Current.LocalFolder.CreateFolderAsync(“文件夹”,CreationCollisionOption.OpenIfExists);
StorageFile f=wait d.CreateFileAsync(“index.html”,CreationCollisionOption.ReplaceExisting);
Stream str=wait f.OpenStreamForWriteAsync();
使用(StreamWriter sw=新StreamWriter(str))
{
sw.写(“…”);
}
string url=“ms”-appdata:///local/folder/index.html";
webView1.导航(新Uri(url));

为了澄清NeoSvet的答案:
ms appdata
仅当您将html文件存储在LocalFolder的子文件夹中而不是根文件夹中时才有效,如下所示:
“ms-appdata:///local/[子文件夹名称]/index.html“


简而言之,我们将详细介绍其原因:这样做是为了为web内容提供某种程度的隔离,从而WebView不会意外地公开本地文件夹中的其他内容

你在哪里打开了zip文件?如果它位于应用程序数据文件夹中,您是否尝试过使用“ms”-appdata:///local/“作为uri的开始?StorageFile.Path变量的值是
C:/Data/Users/DefApps/APPDATA/Local/Packages/cd0b1e93-4db9-4f31-ae6a-6d606d6b9e71\u n2dsc9ch8qzm0/LocalState/JavaBridgeTestunzip/index.html
是的,我已经尝试了NavigateLocalStreamURI()方法,但我没有得到IUriToStreamResolver,也找不到任何帮助。可能需要谷歌一点来让它工作。谢谢你的帮助