D.madushanka
D.madushanka

Reputation: 563

Xamarin forms webview takes all the screen height

I have a webview in one of my page and I want to add a stacklayout from the top then the webview. But Webview take whole screen and the stacklayout never get shown. I want to hide default navigation bar and create my own one. I still couldn't test for the apple side

<?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>

Code behind

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;

    }

}

Upvotes: 0

Views: 269

Answers (1)

nevermore
nevermore

Reputation: 15816

The cause is you set the Content = webView in code behind which means the the whole content is webview and those code in the Xaml will be overwritten.

Solution:

Remove Content = webView; and try again.

Upvotes: 1

Related Questions