[英]Xamarin.Forms: can grid cell include several labels?
One of the grid cells looks like this:网格单元之一如下所示:
<Label Text="{Binding Address1}" FontSize="12" TextColor="Black" Grid.Row="1" Grid.Column="0"/>
This displays Address1
which is correct.这将显示正确的Address1
。
But instead of just showing Address1
, I would like to display Address1
, City
, St
, each with a different FontSize
.但我想显示Address1
、 City
、 St
,而不是只显示Address1
,每个都有不同的FontSize
。
Can this be done without altering the number of rows and columns in the grid?这可以在不改变网格中的行数和列数的情况下完成吗?
One way is to place a StackLayout at the Grid row|column and then separately format each element within it:一种方法是将 StackLayout 放在 Grid 行|列,然后分别格式化其中的每个元素:
<Grid....
~~~
<StackLayout Grid.Row="1" Grid.Column="0">
<Label Text="{Binding Address1}" FontSize="12" TextColor="Black" />
<StackLayout Orientation="Horizontal" >
<Label Text="{Binding City}" FontSize="10" TextColor="Black" />
<Label Text="{Binding St}" FontSize="10" TextColor="Black" />
</StackLayout>
<StackLayout>
~~~
</Grid>
Sure, you would use:当然,你会使用:
<StackLayout Grid.Row="1" Grid.Column="0">
<Label Text="l1"/>
<Label Text="l2"/>
<Label Text="l3"/>
</StackLayout>
You can use other layouts such as StackLayout inside of your Grid as others suggested but you can also put multiple Views inside a Grid cell by setting the same Grid.Row
and Grid.Column
for them and by setting HorizontalOptions
and VerticalOptions
of views inside the Grid you can choose each view position.您可以按照其他人的建议在您的 Grid 内使用其他布局,例如 StackLayout,但您也可以通过为它们设置相同的Grid.Row
和Grid.Column
并通过在 Grid 内设置视图的HorizontalOptions
和VerticalOptions
来将多个视图放Grid.Column
格单元格中您可以选择每个视图位置。
For Example:例如:
<Grid....
~~~
<Label Grid.Row="0" Grid.Column="1" HorizontalOptions="Start" VerticalOptions="Start" Text="{Binding Address1}" FontSize="12" TextColor="Black" />
<Label Grid.Row="0" Grid.Column="1" HorizontalOptions="Start" VerticalOptions="End" Text="{Binding City}" FontSize="10" TextColor="Black" />
<Label Grid.Row="0" Grid.Column="1" HorizontalOptions="End" VerticalOptions="End" Text="{Binding St}" FontSize="10" TextColor="Black" />
~~~
</Grid>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.