In my general Xamarin portable project, this works on UWP, Windows Phone 8.1 and Windows 8.1:
HtmlWebViewSource htmlSource = new HtmlWebViewSource(); htmlSource.Html = @"<html><body><img src='ms-appx-web:///Assets/somePicture.png' /></body></html>"; htmlSource.BaseUrl = DependencyService.Get<IBaseUrl>().Get(); WebView webView = new WebView { Source = htmlSource, };
Obviously, this is not cross-platform (iOS and Android). I want this, but it does not work on UWP, Windows Phone 8.1 and Windows 8.1:
HtmlWebViewSource htmlSource = new HtmlWebViewSource(); htmlSource.Html = @"<html><body><img src='somePicture.png' /></body></html>"; htmlSource.BaseUrl = DependencyService.Get<IBaseUrl>().Get(); WebView webView = new WebView { Source = htmlSource, };
IBaseUrl:
public interface IBaseUrl { string Get(); }
BaseUrl implementation for UWP, Windows Phone 8.1 and Windows 8.1, taken from Windows Phone 8.0 project example :
[assembly: Dependency(typeof(MyApp.UWP.BaseUrl))] namespace MyApp.UWP { public class BaseUrl : IBaseUrl { public string Get() { return "";
I tried different options for returning BaseUrl from ms-appx-web: /// Assets / "," ms-appx-web: /// ", placing files in the root of the project or in" Assets ", nothing works.
As far as I can tell, this worked on Windows Phone 8.0.