【问题标题】:Xamarin Forms' WebView - local assets not found on Windows PhoneXamarin Forms 的 WebView - 在 Windows Phone 上找不到本地资产
【发布时间】:2016-09-13 15:46:39
【问题描述】:

我正在使用 WebView 从字符串中显示 HTML。此 HTML 引用了我在设备上本地拥有的样式表。我按照the official docs 的说明进行操作,以便可以访问本地 CSS 文件。它在 Android 和 iOS 上运行良好,但我无法在 Windows Phone 8.1 上运行。我将 CSS 文件放在项目的根目录中,并将构建操作设置为 Content,然后将 BaseUrl 设置为 ""(我也尝试了 ms-appx-web:///,但没有成功)。

有人知道文档是否缺少一些说明吗?或者它是表单中的错误?任何帮助将不胜感激。

以下是用数据填充 WebView 的代码(在 Forms PCL 中):

private async Task LoadData()
{
    string html = await _dataProvider.GetHtmlAsync("index");
    WebView.Source = new HtmlWebViewSource
    {
        Html = html,
        BaseUrl = _baseUrlProvider.Get()
    };
}

_baseUrlProvider 是我的WebViewBaseUrlProvider 的一个实例,其定义如下:

internal class WebViewBaseUrlProvider : IWebViewBaseUrlProvider
{
    public string Get() => "";
}

编辑:

看到 this question 让我相信 Xamarin Forms 中确实存在错误。当 HTML 中的链接包含整个 ms-appx-web:///style.css 而不仅仅是 style.css 时,它会突然开始工作。显然,这不是完全跨平台的......

【问题讨论】:

  • 你能分享你为加载html文件编写的完整代码吗?
  • 当然,我刚刚编辑了这个问题。您提到的答案对通用应用程序有效。我的目标是 Windows Phone 8.1。

标签: xamarin webview windows-phone-8.1 xamarin.forms


【解决方案1】:
猜你喜欢
  • 2018-08-20
  • 1970-01-01
  • 1970-01-01
  • 2014-10-20
  • 2019-06-30
  • 1970-01-01
  • 2017-07-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多