0
在我的应用程序中,我应该插入一个Markdown渲染。我发现这个组件http://thatcsharpguy.com/post/markdownview-xamarin-forms-control/和渲染工作正常,但我有一个问题,WebView。如果我通过一个web视图的东西,它总是转到错误和错误是:Xamarin Forms WebView错误
对象引用不设置到对象的实例
的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;
}
我创建了接口
public interface IBaseUrl {
string Get();
}
及其每个平台
的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:///";
}
}
}
有什么不对?预先感谢您的帮助。
什么特定的行引发异常? – Jason
始终在此代码之外。在UnhandledException中的UWP + =(sender,e)=> if(global :: System.Diagnostics.Debugger.IsAttached)global :: System.Diagnostics.Debugger.Break(); }; – Enrico
只有UWP引发异常?或者,那只是你正在测试的平台?堆栈跟踪说什么? – Jason