0

在我的应用程序中,我应该插入一个Markdown渲染。我找到了这个组件http://thatcsharpguy.com/post/markdownview-xamarin-forms-control/并且渲染工作正常,但是WebView有问题。如果我将某些东西传递给 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();
 }

及其针对每个平台的实现

机器人

[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:///";
        }
    }
}

怎么了?预先感谢您的帮助。

4

1 回答 1

0

谢谢你的电邮。最后我明白了问题所在。错误来自 Markdown 组件。

于 2016-11-23T00:36:26.587 回答