如何在 xamarin 表单 webview 中加载本地 html 文件 [英] How to load a local html file in a xamarin forms webview
本文介绍了如何在 xamarin 表单 webview 中加载本地 html 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试加载一个 html 文件,该文件与我正在使用的类在同一路径中通过 xamarin 表单中的 Web 视图,当我运行该应用程序时,我得到一个白屏,但没有加载任何内容,这是我的代码:
I am trying to load a html file that is in the same path as class i'm working with Via a web view in xamarin forms when I run the app I get a white screen and nothing loads here's my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace App.Plan
{
public partial class Tornado : ContentPage
{
public Tornado()
{
InitializeComponent();
var browser = new WebView
{
Source = "local.html"
};
}
}
}
推荐答案
Xamarin 有与此相关的文档:
Xamarin has docs in relation to this:
https://developer.xamarin.com/guides/xamarin-forms/user-interface/webview/
var browser = new WebView();
var htmlSource = new HtmlWebViewSource();
htmlSource.Html = @"<html><body>
<h1>Xamarin.Forms</h1>
<p>Welcome to WebView.</p>
</body></html>";
browser.Source = htmlSource;
这篇关于如何在 xamarin 表单 webview 中加载本地 html 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文