Load local html file in WebView Metro Style app

前端 未结 3 1097
独厮守ぢ
独厮守ぢ 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:36

    Here is a quick sample tell me if this help you:

    I have an Html file in my Assets folder called MyHTMLPage, it has a build action of type content and a Copy to Output to Copy Always. My Html file:

    
    
    
    
        
        
    
    
    
    HELLO WORLD, from a webview

    On my Main Page.xaml:

     
            
        
    

    On my Main Page.cs:

     public sealed partial class MainPage : Page
        {
            public MainPage()
            {
                this.InitializeComponent();
                Loaded += MainPage_Loaded;
            }
    
            private void MainPage_Loaded(object sender, RoutedEventArgs e)
            {
                string src = "ms-appx-web:///Assets/MyHTMLPage.html";
                this.MyWebView.Navigate(new Uri(src));
            }
        }
    

    and Voila this should work.

提交回复
热议问题