C# Xaml中的按钮位置
我正在尝试使用Xaml或代码隐藏在屏幕底部定位一个按钮。这就是我努力实现的目标: 以下是Xaml:C# Xaml中的按钮位置,c#,xaml,xamarin,C#,Xaml,Xamarin,我正在尝试使用Xaml或代码隐藏在屏幕底部定位一个按钮。这就是我努力实现的目标: 以下是Xaml: <StackLayout> <Label Text="Identification" x:Name="DriverLabel"/> <Image x:Name="VigoLogo"/> <Entry Placeholder="Driver
<StackLayout>
<Label Text="Identification"
x:Name="DriverLabel"/>
<Image x:Name="VigoLogo"/>
<Entry Placeholder="Driver Name"
Text="{Binding driverID}"/>
<Button Text="Submit"
Command="{Binding Submit}"
x:Name="SubmitButton"
HorizontalOptions="CenterAndExpand"
></Button>
</StackLayout>
我尝试过各种相对和绝对定位的方法,但因为我是新来的沙马林,所以我陷入了比其他任何事情都糟糕的境地。
我使用AbsoluteLayout找到了一些地方,但似乎只有硬编码的x和y坐标起作用,但它需要比不同设备的更动态
任何帮助都将不胜感激 您可以使用网格来执行此操作。我们可以定义4行(从索引“0”开始)。 最后一行(索引3)可以设置为占用所有剩余空间,因此按钮可以放置在垂直选项到结束的位置,以保持粘在底部
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label Text="Identification" Grid.Row="0"
x:Name="DriverLabel"/>
<Image x:Name="VigoLogo" Grid.Row="1"/>
<Entry Placeholder="Driver Name" Grid.Row="2"
Text="{Binding driverID}"/>
<Button Text="Submit" Grid.Row="3"
Command="{Binding Submit}"
x:Name="SubmitButton"
HorizontalOptions="FillAndExpand" VerticalOptions="End"
></Button>
</Grid>
<StackLayout>
<StackLayout VerticalOptions="FillAndExpand">
<Label Text="Identification"
x:Name="DriverLabel"/>
<Image x:Name="VigoLogo" />
<Entry Placeholder="Driver Name"
Text="{Binding driverID}"/>
</StackLayout>
<Button Text="Submit"
Command="{Binding Submit}"
x:Name="SubmitButton"
HorizontalOptions="CenterAndExpand" />
</StackLayout>
我建议您阅读布局,以便为每种情况选择最佳布局
有几个选择 其中之一是使用
StackLayout
包装其他视图,并将垂直选项设置为fillandexpand。这将把按钮推到底部
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label Text="Identification" Grid.Row="0"
x:Name="DriverLabel"/>
<Image x:Name="VigoLogo" Grid.Row="1"/>
<Entry Placeholder="Driver Name" Grid.Row="2"
Text="{Binding driverID}"/>
<Button Text="Submit" Grid.Row="3"
Command="{Binding Submit}"
x:Name="SubmitButton"
HorizontalOptions="FillAndExpand" VerticalOptions="End"
></Button>
</Grid>
<StackLayout>
<StackLayout VerticalOptions="FillAndExpand">
<Label Text="Identification"
x:Name="DriverLabel"/>
<Image x:Name="VigoLogo" />
<Entry Placeholder="Driver Name"
Text="{Binding driverID}"/>
</StackLayout>
<Button Text="Submit"
Command="{Binding Submit}"
x:Name="SubmitButton"
HorizontalOptions="CenterAndExpand" />
</StackLayout>
太好了,谢谢。我会接受这个儿子,因为它让我。