[英]xamarin.forms - I am having layout issues with StackLayout
我正在使用 xamarin.forms StackedLayout,如下所示:
<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>
哪個工作得很好! 我並排有 3 個 StackLayout,這正是我想要的,現在我想添加另一個 StackLayout,它將位於 3 個 StackLayouts 下方,我該怎么做? 我嘗試添加第 4 個 StackLayout,但它繼續並排並且不在第 3 個 StackLayout 之下……這是我要添加的第 4 個 StackLayout……
<StackLayout HorizontalOptions="FillAndExpand">
<Button x:Name="GenerateContract" Text="Generate Contract" Clicked="OnGenerateContract" Style="{StaticResource ButtonStyle}" />
</StackLayout>
我該如何解決?
我還嘗試了以下方法:
<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>
但是我收到了一個帶有 GenerateContract 按鈕的 StackLayout 錯誤:
屬性“內容”設置了不止一次。
更新
我嘗試了以下並得到相同的結果....4 StackLayout並排:
<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>
您需要添加另一個包含水平的垂直StackLayout
<!-- 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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.