Reputation: 1759
How to display label text in multi-line format, as-
First Name
Last Name
Date of birth
All this should appear in single cell of the grid.
This is what I have tried:
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);
Upvotes: 0
Views: 2601
Reputation: 66
try this code snippets, may help
<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=" Moving Average Today"/>
</FormattedString>
</Label.FormattedText>
</Label>
Upvotes: 1
Reputation: 863
Try doing this
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);
Try adding line breaker.
For different font try doing something like this,
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
};
Upvotes: 1