加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何在C#中使用HTML源代码在Xamarin.Forms页面中显示HTML?

发布时间:2020-12-15 04:18:31 所属栏目:百科 来源:网络整理
导读:我编写了这段代码,试图在网页中显示几行 HTML: 我有这个XAML: ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:Japanese;assembly=Test" x:Class="Test.H
我编写了这段代码,试图在网页中显示几行 HTML:

我有这个XAML:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    xmlns:local="clr-namespace:Japanese;assembly=Test" 
    x:Class="Test.HelpCards" 
    x:Name="HelpCards" 
    Title="Help ? Cards Tab">
    <ContentPage.Content>
        <ScrollView>
            <StackLayout Spacing="10" Margin="20">
               <WebView x:Name="Browser" />
            </StackLayout>
        </ScrollView>
    </ContentPage.Content>
</ContentPage>

    public HelpCards()
    {
        InitializeComponent();
        var htmlSource = new HtmlWebViewSource();
        htmlSource.Html = @"<html><body>
        <h1>ABC</h1>
        <p>DEF</p>
        </body></html>";
        Browser.Source = htmlSource;
    }

但是,在运行代码时,我只看到一个空白页面.

有没有人对什么可能是错的有任何想法?

解决方法

确保为WebView指定layout-options.
<ContentPage.Content>
    <ScrollView> <!-- ScrollView not needed as WebView has inbuilt scrolling behavior -->
        <StackLayout Spacing="10" Margin="20">
           <WebView x:Name="Browser" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" />
        </StackLayout>
    </ScrollView>
</ContentPage.Content>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读