使用NavigateToLocalStreamUri的WebView实际上并不导航

Dav*_*ave 1 c# xaml windows-runtime windows-8.1

我有一个WebView,我用它来从ApplicationData.Current.LocalFolder加载本地文件.我做了一个在WebView上调用Navigate的方法

public override void BrowserNavigateLocal(string fileName)
{
   Uri uri = browser.BuildLocalStreamUri("page", fileName);
   browser.NavigateToLocalStreamUri(uri, new MyStreamUriResolver());
}
Run Code Online (Sandbox Code Playgroud)

我的IUriToStreamResolver看起来像这样

public sealed class MyStreamUriResolver : IUriToStreamResolver
{
    public IAsyncOperation<IInputStream> UriToStreamAsync(Uri uri)
    {
        lock (this)
        {
            if (uri == null)
            {
                throw new Exception();
            }
            string path = uri.AbsolutePath;
            return GetContent(path).AsAsyncOperation();
        }
    }

    private async Task<IInputStream> GetContent(string path)
    {
        try
        {

            Uri localUri = new Uri("ms-appdata:///local/HTML" + path);

            //StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(localUri);
            //IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read);

            StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(localUri).AsTask().ConfigureAwait(false);
            IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read).AsTask().ConfigureAwait(false);

            if (true)
            {
                Windows.Storage.Streams.DataReader reader = new DataReader(stream);
                await reader.LoadAsync((uint)stream.Size);
                string fileContent = reader.ReadString((uint)stream.Size);
                stream.Seek(0);
            }
            return stream;

        }
        catch (Exception ex)
        {
            throw new Exception("Path is invalid");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我已经包含了一些调试代码,允许我检查WebView请求的所有内容的文件内容.文件一切都很好,没有抛出异常.

我对BrowserNavigateLocal()的第一次调用工作正常,但它不会加载我的第二页.WebView只停留在当前页面上.

WebView引发了NavigationStarting和ContentLoading事件,但NavigationCompleted永远不会被第二页命中.

编辑:我可以确认我的第二页上的html导致了问题.我试图导航到一个临时页面,它完美地工作.我仍然不知道如何调试我的第二页.

任何帮助将不胜感激.

Dav*_*ave 5

我想到了.我的html页面正在使用JQuery对本地文件发出ajax请求.在我的ajax请求中,我将"async"标志设置为true.当你这样做时,Windows 8.1显然不喜欢它.