首页 > 解决方案 > Xamarin Forms,Webview 在 Content 顶部留下空白

问题描述

当我使用 webview 时,它的顶部和底部有间隙,或者如果水平放置,它的侧面有间隙。如何让 webview 填满整个屏幕。

您可以在屏幕截图中看到蓝色区域是内容的背景颜色。为什么 webview 不从顶部开始?

我还添加了一个标签,该标签正确地位于屏幕顶部。

    <?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="WorkingWithWebview.MyPage" >
       <ContentPage.Content>
           <StackLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
             <Label Text="this is a label showing its not the nav bar" BackgroundColor="Red"></Label>
             <WebView VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" 
             Source="https://www.google.com" WidthRequest="1000" HeightRequest="1000">

           </WebView>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

在此处输入图像描述

标签: androidioswebviewxamarin.forms

解决方案


<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
<ContentPage.Content>
    <Grid HorizontalOptions="FillAndExpand"
          VerticalOptions="FillAndExpand">
        <WebView HorizontalOptions="FillAndExpand"
                 VerticalOptions="FillAndExpand">
            <WebView.Source>
                <HtmlWebViewSource Html="{Binding TermsAndConditions}"/>
            </WebView.Source>
        </WebView>
    </Grid>
</ContentPage.Content>

这个设置对我很有效 =)


推荐阅读