我编写了这段代码,试图在网页中显示几行
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>