Reputation: 5048
I'm using WebView to display HTML from a string. This HTML references a stylesheet that I have locally on the device. I'm following the instructions from the official docs so the local CSS file can be accessed. It works fine on Android and iOS but I can't make it work on Windows Phone 8.1. I placed the CSS file in the root of the project and set the build action to Content, then set the BaseUrl to ""
(I tried ms-appx-web:///
as well, with no success).
Does anyone know if the docs are missing some instructions? Or is it a bug in Forms? Any help would be appreciated.
Here's the code for populating the WebView with data (in a Forms PCL):
private async Task LoadData()
{
string html = await _dataProvider.GetHtmlAsync("index");
WebView.Source = new HtmlWebViewSource
{
Html = html,
BaseUrl = _baseUrlProvider.Get()
};
}
_baseUrlProvider
is an instance of my WebViewBaseUrlProvider
that is defined as follows:
internal class WebViewBaseUrlProvider : IWebViewBaseUrlProvider
{
public string Get() => "";
}
EDIT:
Seeing this question leads me to believe that there indeed is a bug in Xamarin Forms. When the link in the HTML contains the whole ms-appx-web:///style.css
instead of just style.css
, it suddenly starts to work. Obviously, this is not quite cross-platform...
Upvotes: 0
Views: 558
Reputation: 5048
I just found the answer - Xamarin simply ignores the BaseUrl property: https://github.com/xamarin/Xamarin.Forms/blob/2d9288eee6e6f197364a64308183725e7bd561f9/Xamarin.Forms.Platform.WinRT/WebViewRenderer.cs#L26
Upvotes: 0