Xamarin Form WebView高度作为HTML内容

Mat*_*ekr 6 webview xamarin.forms

在这里,我有一个WebView可以加载3 gif的html页面。我希望WebView变得和HTML内容一样大。这是可能的?在WebView下,我在Label中显示了一些说明

  <Grid>
    <Grid>
      <Grid.RowDefinitions>
        <RowDefinition Height="auto"/>
        <RowDefinition Height="*"/>
        <RowDefinition Height="*"/>
      </Grid.RowDefinitions>
      <Grid Grid.Row="0" >
        <Grid.RowDefinitions>
          <RowDefinition/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*"/>
          <ColumnDefinition Width="*"/>
          <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        ...     
      </Grid>
      <Grid Grid.Row="1">
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
          <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <WebView x:Name="webw1" Grid.Row="0" Grid.Column="0"></WebView>
      </Grid>
      <Grid Grid.Row="2" >
        <Grid.RowDefinitions>
          <RowDefinition/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <ScrollView Grid.Row="0" Grid.Column="0">
          <Label Text="LastExplanation" x:Name="lblLastExplanation" />
        </ScrollView>
      </Grid>
    </Grid>
  </Grid>
</ContentPage>


public FinalCheck()
        {
            InitializeComponent();
            webw1.Source = DependencyService.Get<IBaseUrl>().Get() + "instruction.html";
        }
Run Code Online (Sandbox Code Playgroud)

小智 0

如果不改变,最简单的方法:

<WebView x:Name="webw1" Grid.Row="0" Grid.Column="0" HeightRequest="xxx"></WebView>

或者

您可以创建自定义渲染器或创建一种与您的 html 页面通信的方式来向您发送数据,在这种情况下为高度

如果需要动态/交互,这可能会有所帮助。