in my application I should insert a Markdown render. I found this component http://thatcsharpguy.com/post/markdownview-xamarin-forms-control/ and the render is working fine but I have a problem with the WebView. If I pass to a WebView something, it always goes in error and the error is:
Object reference not set to an instance of an object
Page1.xaml
<xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="WBE.Views.Page1">
<ContentPage.Content>
<StackLayout>
<WebView x:Name="Browser" VerticalOptions="FillAndExpand">
</WebView>
</StackLayout>
</ContentPage.Content>
</ContentPage>
Page1.xaml.cs
public Page1()
{
InitializeComponent();
var htmlSource = new HtmlWebViewSource();
htmlSource.Html = @"<html><body>
<h1>Xamarin.Forms</h1>
<p>Welcome to WebView.</p>
</body></html>";
htmlSource.BaseUrl = DependencyService.Get<IBaseUrl>().Get();
this.Browser.Source = htmlSource;
}
I created my interface
public interface IBaseUrl {
string Get();
}
and its implementations for each platform
Droid
[assembly: Xamarin.Forms.Dependency(typeof(IBaseUrl))]
namespace WBE.Android
{
public class BaseUrl_Android : IBaseUrl
{
public string Get()
{
return "file:///android_asset/";
}
}
}
iOS
[assembly: Xamarin.Forms.Dependency(typeof(IBaseUrl))]
namespace WBE.iOS
{
public class BaseUrl_iOS : IBaseUrl
{
public string Get()
{
return NSBundle.MainBundle.BundlePath;
}
}
}
UWP
[assembly: Dependency(typeof(BaseUrl_UWP))]
namespace WBE.UWP.Dependecies
{
public class BaseUrl_UWP : IBaseUrl
{
public string Get()
{
return "ms-appx-web:///";
}
}
}
What is wrong? Thank you in advance for your help.