在Xamarin Forms中使用Br标记
问题描述:
我正在使用Xamarin Forms。我使用BoxView在线条之间制作空格,但我不知道我是否正确。在Xamarin中使用br标签的正确方法是什么?有没有其他的方法呢?我使用的是这样的:在Xamarin Forms中使用Br标记
<StackLayout>
<Label Text="Line 1"></Label>
<BoxView HeightRequest="100"></BoxView>
<Label Text="Line 2"></Label>
</StackLayout>
感谢您的答复,下结论;我认为最简单的选择应该是这样的,
,通常情况下,我会使用网格来进行间距。
<StackLayout>
<Label Text="10"></Label>
<StackLayout HeightRequest="100"></StackLayout>
<Label Text="20"></Label>
</StackLayout>
答
如果您已经使用了StackLayout,您可以设置在Stackayout,例如每个元素之间的“距离”:
<StackLayout Spacing="10">
一些其他的选择可以在Xamarin论坛虽然被发现.. 。https://forums.xamarin.com/discussion/29700/label-and-n
答
根据您的要求,有多种方法可以做到这一点。
你可以设置你的Label
的Margin
属性,也可以设置你的StackLayout
的Spacing
它告诉StackLayout
把其中的项目之间的一些空间。
另一种方法是将您的StackLayout
更改为Grid
。有了这个,你可以进行更细致的控制,因为你不仅可以像StackLayout
那样设置Spacing
,还可以播放行高和列宽。在Grid
的列和行中,您可以嵌套StackLayout
以获得更多控制权,以便更好地控制这些行为。
有关网格的更多信息,请查看Xamarin Documentation中的详细指南。
答
you can follow the example bellow or use [GRID ][1]
StackLayout linesSTK= new StackLayout {
VerticalOptions = LayoutOptions.Center,
HorizontalOptions =LayoutOptions.CenterAndExpand,
Children = {
new Label { Text = "Line 1" },
new Label { Text = "Line 2" },
new Label { Text = "Line 3" }
}
};
这将为StackLayout中的每一行提供相同的空格,但是当尝试多个StackLayouts时,okey应该很有用,然后我可以给出自定义空间。 –
确实,这取决于设置...看看我提供的论坛链接有更多选项。只需要看看什么最适合你的问题,这个问题有点泛泛而谈;) – Depechie
顺便说一句,这不起作用,但这工作: StackLayout> –