问题描述
我在 StackLayout 中添加了 Label。我已经为 StackLayout 设置了 HeightRequest,为 Label 设置了长文本。
我想裁剪标签中的超出文本。但它会在 StackLayout 之外呈现。如何限制。
我不想为标签设置 HeightRequest。
<StackLayout Margin="10" HeightRequest="42" BackgroundColor="Yellow">
<Label VerticalOptions="Center" Text="A minimum 5 characters password contains a combination of uppercase and lowercase letter and number are required. A minimum 5 characters password contains a combination of uppercase and lowercase letter and number are required."/>
</StackLayout>
解决方法
子视图在 StackLayout
中的大小和位置取决于子视图的 HeightRequest
和 WidthRequest
属性的值,以及它们的 HorizontalOptions
和VerticalOptions
属性。
在垂直 StackLayout 中,当子视图的大小未明确设置时,子视图会扩展以填充可用宽度。同样,在水平 StackLayout 中,当子视图的大小未明确设置时,子视图会扩展以填充可用高度。
有关更多详细信息,您可以参考 MS 文档。 https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/layouts/stacklayout
,为了根据上面代码中的StackLayout设置标签高度,请为stackLayout设置Orientation="Horizontal"
。