C# xamarin.forms-我在StackLayout中遇到布局问题
我正在使用xamarin.forms StackedLayout,如下所示:C# xamarin.forms-我在StackLayout中遇到布局问题,c#,xamarin.forms,C#,Xamarin.forms,我正在使用xamarin.forms StackedLayout,如下所示: <StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand" VerticalOptions="CenterAndExpand"> <StackLayout Margin="5,0,5,0" HorizontalOptions="FillAndExpand"> <Entry x:Na
<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下面,我该如何做?我尝试添加第四个StackLayout,但它继续并排运行,而不是在第三个StackLayout下…这是我尝试添加的第四个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>
但是我得到一个带有GenerateContact按钮的StackLayout错误:
属性“Content”设置了多次
更新
我尝试了以下方法并得到了相同的结果…4并排堆叠布局:
<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>
您需要添加另一个包含水平布局的垂直
堆栈布局
<!-- 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>
...
我试过了,但我得到了一个错误:属性“Content”被设置了不止一次。哦,我想我明白你的意思了,让我试试看。是的,我刚刚试过这个,添加了另一个StackView并包装了水平布局和其他布局,但我得到了相同的结果…我得到了4个并排的StackView。外部StackLayout是否使用了Orientation=“Vertical”
?这是我认为正确的默认设置。GenerateContact按钮应位于其他控件的下方。然而,对于这样的布局,我强烈建议使用网格,而不是许多嵌套的堆栈布局