Xamarin Forms: отображать несколько строк текста в ячейке сетки - PullRequest
0 голосов
/ 12 февраля 2020

Как отобразить текст метки в многострочном формате, как-

First Name
Last Name
Date of birth

Все это должно появиться в одной ячейке сетки.

Вот что я пробовал:

 string full_details = firstname + lastname + dob;
 Label name = new Label
 {
   Text = full_details,
   MaxLines = 3,
   LineBreakMode = LineBreakMode.WordWrap,
   VerticalOptions = LayoutOptions.Center
 };
 grid.Children.Add(name,0,0);

Ответы [ 2 ]

1 голос
/ 12 февраля 2020

Попробуйте сделать это

string full_details = firstname + "\n" + lastname + "\n" + dob;
Label name = new Label
{
   Text = full_details,
   MaxLines = 3,
   LineBreakMode = LineBreakMode.WordWrap,
   VerticalOptions = LayoutOptions.Center
};
grid.Children.Add(name,0,0);

Попробуйте добавить разрыв строки.

Для другого шрифта попробуйте сделать что-то вроде этого,

    var formattedString = new FormattedString ();
    formattedString.Spans.Add (new Span{ Text = firstname , ForegroundColor = Color.Red, FontAttributes = FontAttributes.Bold });

    var span = new Span { Text = "\n" + lastname };
    formattedString.Spans.Add(span);
    formattedString.Spans.Add (new Span { Text = "\n" +dob, FontAttributes = FontAttributes.Italic, FontSize =  Device.GetNamedSize(NamedSize.Small, typeof(Label)) });

    Label name = new Label 
    {
        FormattedString = formattedString
    };
0 голосов
/ 12 февраля 2020

попробуйте этот фрагмент кода, может помочь

<Label x:Name="MovAvgLabel" Grid.Column="0" HorizontalOptions="Center" HorizontalTextAlignment="Center" >
    <Label.FormattedText>
        <FormattedString>
            <Span Text="{Binding Path=MovingAverage}" FontSize="Medium" FontAttributes="Bold"/>
            <Span Text="&#10;Moving Average&#10;Today"/>
        </FormattedString>
    </Label.FormattedText>
</Label>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...