[英]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.