[英]Xamarin Forms WebView errors
in my application I should insert a Markdown render. 在我的应用程序中,我应该插入Markdown渲染器。 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 .
我发现该组件http://thatcsharpguy.com/post/markdownview-xamarin-forms-control/且渲染正常,但WebView出现问题。 If I pass to a WebView something, it always goes in error and the error is:
如果我将某些内容传递给WebView,它将始终出错并且错误是:
Object reference not set to an instance of an object
你调用的对象是空的
Page1.xaml 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 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 的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.
预先感谢您的帮助。
thanks for your email. 谢谢你的电邮。 At the end I understood what the problem was.
最后,我了解了问题所在。 The error came from the Markdown component.
该错误来自Markdown组件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.