Load local html file in WebView Metro Style app

前端 未结 3 1059
独厮守ぢ
独厮守ぢ 2021-01-11 17:57

I\'m having a bit of trouble loading an html file in a WebView control in a metro style app. I\'ve been searching the internet and found out that you can\'t load a local htm

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-11 18:35

    I ran into the same problem. In my application I have a file called Default.html which is read and it's contents are displayed in a WebView control.

    var html = await Windows.Storage.PathIO.ReadTextAsync("ms-appx:///Assets/Default.html");
    MyWebView.NavigateToString(html);
    

    Note that I'm using await and ReadTextAsync so that the code is asynchronous (as one should when doing IO), the function you place this snipped it must be defined as async, example:

    private async void LoadWebView( file ) { ... }
    

提交回复
热议问题