Xamarin表单Webview不会显示所有内容

时间:2018-08-25 11:52:38

标签: c# xamarin webview xamarin.forms

我有一个简单的Webview,我想在其中显示一些html文本 我得到一些有趣的结果:

output

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="SongManager.Text.TextViewer"
             Title="{Binding Title}">
    <ContentPage.Content>
        <WebView x:Name="web" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
        </WebView>
    </ContentPage.Content>
</ContentPage>

代码:

public partial class TextViewer : ContentPage
{
    TextModel _model;
    IInstanceService _instanceService;
    SongItem song;
    public TextViewer(IInstanceService instanceService, SongItem item)
    {
        _instanceService = instanceService;
        InitializeComponent();
        BindingContext = _model = new TextModel();
        song = item;
        _model.Title = $"{song.artistName} - {song.name}";
    }

    protected override async void OnAppearing()
    {
        base.OnAppearing();
        WfDataCollection data = await _instanceService.Get(DataDesignEndpoints.OsmSong, song.code);
        if (data.HasData && data.Tables[4].Data != null)
        {
            _model.Text = data.Tables[4].Data[0].Value<string>("description");
            web.Source = _model.Html;
        }
    }

型号:

  class TextModel : BaseModel, INotifyPropertyChanged
{
    public string Title { get; set; }
    public string Text { get; set; }
    public HtmlWebViewSource Html { get {
            return new HtmlWebViewSource
            {
                Html = $"<html><body>{Text}</body></html>" 
            };
        } }
}  

HTML:

<html>
<body>
<div class="G1VCxe kno-fb-ctx" style="margin-top: 12px; color: #222222; font-family: arial, sans-serif; font-size: small;">
<div style="line-height: 1.24; margin-bottom: 12px; text-align: center;"><span style="color: rgba(0, 0, 0, 0.87); font-family: arial, sans-serif-light, sans-serif; font-size: 30px;">Angels</span></div>
<div style="line-height: 1.24; margin-bottom: 12px; text-align: center;"><a style="color: #660099; cursor: pointer; text-decoration-line: none;" href="https://www.google.com/search?q=Robbie+Williams&amp;stick=H4sIAAAAAAAAAONgVuLQz9U3sCwsMgMAfs4EgwwAAAA&amp;sa=X&amp;ved=2ahUKEwjM7r-W-YfdAhUIjqQKHTnRAucQMTAAegQIBhAF" data-ved="2ahUKEwjM7r-W-YfdAhUIjqQKHTnRAucQMTAAegQIBhAF">Robbie Williams</a></div>
<div style="line-height: 1.24; margin-bottom: 12px; text-align: center;">I sit and wait<br />Does an angel contemplate my fate<br />And do they know<br />The places where we go<br />When we're grey and old<br />'Cause I have been told<br />That salvation lets their wings unfold<br />So when I'm lying in my bed<br />Thoughts running through my head<br />And I feel the love is dead<br />I'm loving angels instead</div>
<div style="line-height: 1.24; margin-bottom: 12px; text-align: center;">And through it all she offers me protection<br />A lot of love and affection<br />Whether I'm right or wrong<br />And down the waterfall&nbsp;<br />Wherever it may take me<br />I know that life won't break me<br />When I come to call, she won't forsake me<br />I'm loving angels instead</div>
<div style="line-height: 1.24; margin-bottom: 12px; text-align: center;">When I'm feeling weak<br />And my pain walks down a one way street<br />I look above<br />And I know I'll always be blessed with love<br />And as the feeling grows<br />She breathes flesh to my bones<br />And when love is dead<br />I'm loving angels instead</div>
</div>
<div class="G1VCxe kno-fb-ctx" style="color: #222222; font-family: arial, sans-serif; font-size: small;">
<div class="iw7h9e" style="line-height: 1.24; margin-bottom: 12px; text-align: center;" data-mh="-1">And through it all she offers me protection<br />A lot of love and affection<br />Whether I'm right or wrong<br />And down the waterfall&nbsp;<br />Wherever it may take me<br />I know that life won't break me<br />When I come to call, she won't forsake me<br />I'm loving angels instead</div>
<div class="xpdxpnd" style="overflow: hidden; transition: max-height 0.3s ease 0s; max-height: 128px; line-height: 1.24; margin-bottom: 0px; text-align: center;" data-mh="128" data-mhc="1">And through it all she offers me protection<br />A lot of love and affection<br />Whether I'm right or wrong<br />And down the waterfall&nbsp;<br />Wherever it may take me<br />I know that life won't break me<br />When I come to call, she won't forsake me<br />I'm loving angels instead</div>
</div>
</bod>
</html>

任何人都有一个想法,为什么它会被切断?基本上最后两行被剪掉

0 个答案:

没有答案