如何在Xamarin Forms中向标签添加垂直滚动?

时间:2018-10-22 09:25:03

标签: xamarin xamarin.forms

我有一个大文本,我想显示它。我为此使用标签。但是此标签不显示全文。我想要此标签的垂直滚动。

Grid mainGrid = new Grid
{
    HeightRequest = 40,
    BackgroundColor = Color.White,
    Padding = 20,
    RowDefinitions =
    {

        new RowDefinition { Height = new GridLength(25, GridUnitType.Star) },//0 Title
        new RowDefinition { Height = new GridLength(5, GridUnitType.Star) },//1 Line
        new RowDefinition { Height = new GridLength(50, GridUnitType.Star) },//2 This is for MessageLabel
        new RowDefinition { Height = new GridLength(20, GridUnitType.Star) },//3 OK-Cancel
    }
};    

MessageLabel = new Label
{
    FontAttributes = FontAttributes.None,
    FontSize = 18,
    HorizontalTextAlignment = TextAlignment.Start,
    VerticalTextAlignment = TextAlignment.Center,
    HorizontalOptions = LayoutOptions.StartAndExpand,
    TextColor = Color.Black,
};

mainGrid.Children.Add(MessageLabel, 0, 2);

我为此标签尝试了不同的VerticalOptions,但没有任何效果。

如果标签不支持此功能。我可以使用其他控件吗?

2 个答案:

答案 0 :(得分:1)

如果要垂直滚动,则必须使用ScrollView,将标签/网格包裹在scrollview中,然后才能显示所有文本。

<ScrollView>

<Grid/>

</ScrollView/>

答案 1 :(得分:0)

谢谢Bruno Caceiro的提示。我已经用他提供的提示解决了这个问题。

uml:Something
相关问题