简体   繁体   中英

xamarin.forms - I am having layout issues with StackLayout

I am using xamarin.forms StackedLayout like so:

<StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand" VerticalOptions="CenterAndExpand">

    <StackLayout Margin="5,0,5,0" HorizontalOptions="FillAndExpand">
        <Entry x:Name="Community" WidthRequest="200" Placeholder="Community" />
        <Entry x:Name="Job" WidthRequest="200" Placeholder="Job" />
        <Entry x:Name="Model" WidthRequest="200" Placeholder="Model" />
        <Entry x:Name="Elevation" WidthRequest="200" Placeholder="Elevation" />
        <Entry x:Name="Email" WidthRequest="200" Placeholder="Email" />
        <Entry x:Name="C_Email" WidthRequest="200" Placeholder="C_Email" />
        <Entry x:Name="Buyer_Salutation" WidthRequest="200" Placeholder="Buyer_Salutation" />
        <Button x:Name="FrontCamera" Text="Front Licence" Clicked="OnFrontCamera" Style="{StaticResource ButtonStyle}" />
    </StackLayout>
    <StackLayout Margin="5,0,5,0" HorizontalOptions="FillAndExpand">

        <Entry x:Name="Customer_Name" WidthRequest="200" Placeholder="Customer_Name" />
        <Entry x:Name="Customer_LName" WidthRequest="200" Placeholder="Customer_LName" />
        <Entry x:Name="C_Buyer_Salutation" WidthRequest="200" Placeholder="C_Buyer_Salutation" />
        <Entry x:Name="CoBuyer_Name" WidthRequest="200" Placeholder="CoBuyer_Name" />
        <Entry x:Name="CoBuyer_LName" WidthRequest="200" Placeholder="CoBuyer_LName" />
        <Entry x:Name="Address1" WidthRequest="200" Placeholder="Address1" />
        <Entry x:Name="City" WidthRequest="200" Placeholder="City" />
        <Button x:Name="BackCamera" Text="Back Licence" Clicked="OnBackCamera" Style="{StaticResource ButtonStyle}" />

    </StackLayout>
    <StackLayout Margin="5,0,5,0" HorizontalOptions="FillAndExpand">

        <Entry x:Name="Phone1Cell" WidthRequest="200" Placeholder="Phone1Cell" />
        <Entry x:Name="Phone1Work" WidthRequest="200" Placeholder="Phone1Work" />
        <Entry x:Name="Phone2Main" WidthRequest="200" Placeholder="Phone2Main" />
        <Entry x:Name="Phone2Cell" WidthRequest="200" Placeholder="Phone2Cell" />
        <Entry x:Name="Phone2Work" WidthRequest="200" Placeholder="Phone2Work" />
        <Entry x:Name="Province" WidthRequest="200" Placeholder="Province" />
        <Entry x:Name="Zip" WidthRequest="200" Placeholder="Zip" />
        <Button x:Name="ScanLicence" Text="Scan Licence" Clicked="OnCameraScan" Style="{StaticResource ButtonStyle}" />
        <zxing:ZXingScannerView x:Name="BarcodeScanView" IsVisible="false" HeightRequest="200" OnScanResult="Handle_OnScanResult" />

    </StackLayout>

</StackLayout>

Which is working great! I have 3 StackLayout side by side which is exactly what I wanted, now I am looking to add another StackLayout that will go below the 3 StackLayouts, how would I do that? I tried add a 4th StackLayout, but it continues to go side by side and not under neither the 3 StackLayout...Here is the 4th StackLayout I am trying to add...

<StackLayout HorizontalOptions="FillAndExpand">
        <Button x:Name="GenerateContract" Text="Generate Contract" Clicked="OnGenerateContract" Style="{StaticResource ButtonStyle}" />
    </StackLayout>

How do I fix this?

I also tried the following:

<StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand" VerticalOptions="CenterAndExpand">

    <StackLayout Margin="5,0,5,0" HorizontalOptions="FillAndExpand">
        <Entry x:Name="Community" WidthRequest="200" Placeholder="Community" />
        <Entry x:Name="Job" WidthRequest="200" Placeholder="Job" />
        <Entry x:Name="Model" WidthRequest="200" Placeholder="Model" />
        <Entry x:Name="Elevation" WidthRequest="200" Placeholder="Elevation" />
        <Entry x:Name="Email" WidthRequest="200" Placeholder="Email" />
        <Entry x:Name="C_Email" WidthRequest="200" Placeholder="C_Email" />
        <Entry x:Name="Buyer_Salutation" WidthRequest="200" Placeholder="Buyer_Salutation" />
        <Button x:Name="FrontCamera" Text="Front Licence" Clicked="OnFrontCamera" Style="{StaticResource ButtonStyle}" />
    </StackLayout>
    <StackLayout Margin="5,0,5,0" HorizontalOptions="FillAndExpand">

        <Entry x:Name="Customer_Name" WidthRequest="200" Placeholder="Customer_Name" />
        <Entry x:Name="Customer_LName" WidthRequest="200" Placeholder="Customer_LName" />
        <Entry x:Name="C_Buyer_Salutation" WidthRequest="200" Placeholder="C_Buyer_Salutation" />
        <Entry x:Name="CoBuyer_Name" WidthRequest="200" Placeholder="CoBuyer_Name" />
        <Entry x:Name="CoBuyer_LName" WidthRequest="200" Placeholder="CoBuyer_LName" />
        <Entry x:Name="Address1" WidthRequest="200" Placeholder="Address1" />
        <Entry x:Name="City" WidthRequest="200" Placeholder="City" />
        <Button x:Name="BackCamera" Text="Back Licence" Clicked="OnBackCamera" Style="{StaticResource ButtonStyle}" />

    </StackLayout>
    <StackLayout Margin="5,0,5,0" HorizontalOptions="FillAndExpand">

        <Entry x:Name="Phone1Cell" WidthRequest="200" Placeholder="Phone1Cell" />
        <Entry x:Name="Phone1Work" WidthRequest="200" Placeholder="Phone1Work" />
        <Entry x:Name="Phone2Main" WidthRequest="200" Placeholder="Phone2Main" />
        <Entry x:Name="Phone2Cell" WidthRequest="200" Placeholder="Phone2Cell" />
        <Entry x:Name="Phone2Work" WidthRequest="200" Placeholder="Phone2Work" />
        <Entry x:Name="Province" WidthRequest="200" Placeholder="Province" />
        <Entry x:Name="Zip" WidthRequest="200" Placeholder="Zip" />
        <Button x:Name="ScanLicence" Text="Scan Licence" Clicked="OnCameraScan" Style="{StaticResource ButtonStyle}" />
        <zxing:ZXingScannerView x:Name="BarcodeScanView" IsVisible="false" HeightRequest="200" OnScanResult="Handle_OnScanResult" />

    </StackLayout>

</StackLayout>
<StackLayout HorizontalOptions="FillAndExpand">
        <Button x:Name="GenerateContract" Text="Generate Contract" Clicked="OnGenerateContract" Style="{StaticResource ButtonStyle}" />
 </StackLayout>

But I get an error for the StackLayout with GenerateContract button:

The property 'Content' is set more than once.

UPDATE

I have tried the following and get the same result....4 StackLayout side by side:

<StackLayout Orientation="Vertical">

        <StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand" VerticalOptions="CenterAndExpand">

            <StackLayout Margin="5,0,5,0" HorizontalOptions="FillAndExpand">
                <Entry x:Name="Community" WidthRequest="200" Placeholder="Community" />
                <Entry x:Name="Job" WidthRequest="200" Placeholder="Job" />
                <Entry x:Name="Model" WidthRequest="200" Placeholder="Model" />
                <Entry x:Name="Elevation" WidthRequest="200" Placeholder="Elevation" />
                <Entry x:Name="Email" WidthRequest="200" Placeholder="Email" />
                <Entry x:Name="C_Email" WidthRequest="200" Placeholder="C_Email" />
                <Entry x:Name="Buyer_Salutation" WidthRequest="200" Placeholder="Buyer_Salutation" />
                <Button x:Name="FrontCamera" Text="Front Licence" Clicked="OnFrontCamera" Style="{StaticResource ButtonStyle}" />
            </StackLayout>
            <StackLayout Margin="5,0,5,0" HorizontalOptions="FillAndExpand">

                <Entry x:Name="Customer_Name" WidthRequest="200" Placeholder="Customer_Name" />
                <Entry x:Name="Customer_LName" WidthRequest="200" Placeholder="Customer_LName" />
                <Entry x:Name="C_Buyer_Salutation" WidthRequest="200" Placeholder="C_Buyer_Salutation" />
                <Entry x:Name="CoBuyer_Name" WidthRequest="200" Placeholder="CoBuyer_Name" />
                <Entry x:Name="CoBuyer_LName" WidthRequest="200" Placeholder="CoBuyer_LName" />
                <Entry x:Name="Address1" WidthRequest="200" Placeholder="Address1" />
                <Entry x:Name="City" WidthRequest="200" Placeholder="City" />
                <Button x:Name="BackCamera" Text="Back Licence" Clicked="OnBackCamera" Style="{StaticResource ButtonStyle}" />

            </StackLayout>
            <StackLayout Margin="5,0,5,0" HorizontalOptions="FillAndExpand">

                <Entry x:Name="Phone1Cell" WidthRequest="200" Placeholder="Phone1Cell" />
                <Entry x:Name="Phone1Work" WidthRequest="200" Placeholder="Phone1Work" />
                <Entry x:Name="Phone2Main" WidthRequest="200" Placeholder="Phone2Main" />
                <Entry x:Name="Phone2Cell" WidthRequest="200" Placeholder="Phone2Cell" />
                <Entry x:Name="Phone2Work" WidthRequest="200" Placeholder="Phone2Work" />
                <Entry x:Name="Province" WidthRequest="200" Placeholder="Province" />
                <Entry x:Name="Zip" WidthRequest="200" Placeholder="Zip" />
                <Button x:Name="ScanLicence" Text="Scan Licence" Clicked="OnCameraScan" Style="{StaticResource ButtonStyle}" />
                <zxing:ZXingScannerView x:Name="BarcodeScanView" IsVisible="false" HeightRequest="200" OnScanResult="Handle_OnScanResult" />

            </StackLayout>

        </StackLayout>

        <StackLayout HorizontalOptions="FillAndExpand" Orientation="Vertical">
            <Button x:Name="GenerateContract" Text="Generate Contract" Clicked="OnGenerateContract" Style="{StaticResource ButtonStyle}" />
        </StackLayout>

    </StackLayout>

you need to add another Vertical StackLayout containing your Horizontal ones

<!-- new vertical container -->
<StackLayout>

    <!-- existing Horizontal Layout -->
    <StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand" VerticalOptions="CenterAndExpand">
    ...
    </StackLayout>

    <!-- 2nd layout that is underneath your horizontal layouts
    <StackLayout HorizontalOptions="FillAndExpand">
      <Button x:Name="GenerateContract" Text="Generate Contract" Clicked="OnGenerateContract" Style="{StaticResource ButtonStyle}" />
    </StackLayout>

</StackLayout>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM