Xamarin表单Webview占据了所有屏幕高度

时间:2020-05-09 05:46:55

标签: android xamarin.forms

我在页面之一中有一个webview,我想从顶部再在webview中添加一个堆栈布局。但是Webview占据了整个屏幕,并且堆栈布局从未显示出来。我想隐藏默认导航栏并创建自己的导航栏。我仍然无法测试苹果方面

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage  xmlns:other="clr-namespace:CustApp.CusApp.Dushan.Other"
             xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             EnableBackButtonOverride="True"
             x:Class="CustApp.Views.GeneralPayments.MotorPayments.hnb.HNBmotorPayment">
    <ContentPage.Content>

        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="100"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>

            <StackLayout Grid.Row="0" VerticalOptions="Start" HorizontalOptions="FillAndExpand" Orientation="Horizontal" Padding="10,5,10,5">

                <Image HorizontalOptions="StartAndExpand" Source="pdfDown.png"/>
                <Label HorizontalOptions="CenterAndExpand" Text="ALL"/>
                <Image HorizontalOptions="EndAndExpand" Source="pdfDown.png"/>

            </StackLayout>

            <WebView Grid.Row="1" x:Name="webView" 
                 HorizontalOptions="CenterAndExpand" 
                 Navigating="webView_Navigating" 
                 Navigated="MywebView_Navigated"/>


        </Grid>

    </ContentPage.Content>
</ContentPage>

后面的代码

protected override void OnAppearing()
{
    base.OnAppearing();
    NavigationPage.SetHasNavigationBar(this, false);
    if (isFirstRun)
    {

        jsonOutput = JsonConvert.SerializeObject(payData);

        //var htmlSource = new HtmlWebViewSource();
        var urlSource = new UrlWebViewSource();

        string url = DependencyService.Get<IBaseUrl>().Get();

        TempUrl = Path.Combine(url, "xamarinhtmlmotor.html");
        urlSource.Url = TempUrl;
        webView.Source = urlSource;

        isFirstRun = false;

        Content = webView;

    }

}

1 个答案:

答案 0 :(得分:1)

原因是您在后面的代码中设置了 Content = webView ,这意味着全部内容都是webview,而Xaml中的代码将被覆盖。

解决方案:

删除Content = webView;,然后重试。