我怎样才能在网格中制作粗体文本的一半?
How can i make bold half of text in grid?
我在网格中有一些文本。我需要把它的一半加粗,另一半应该是正常的。我怎样才能做到?例如;
gr.Children.Add(new Label
{
Text = $"Min. Adet : {data}",
TextColor = Color.FromHex("#22223b"),
FontSize = 16
}, 3, 3);
我需要将 bold = "Min. Adet : " 和 "{data}" 设为正常。我怎样才能做到?感谢您的帮助!!!
使用Span and FormattedText
var layout = new StackLayout{ Padding = new Thickness (5, 10) };
...
var formattedString = new FormattedString ();
formattedString.Spans.Add (new Span{ Text = "Red bold, ", ForegroundColor = Color.Red, FontAttributes = FontAttributes.Bold });
var span = new Span { Text = "default, " };
span.GestureRecognizers.Add(new TapGestureRecognizer { Command = new Command(async () => await DisplayAlert("Tapped", "This is a tapped Span.", "OK")) });
formattedString.Spans.Add(span);
formattedString.Spans.Add (new Span { Text = "italic small.", FontAttributes = FontAttributes.Italic, FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)) });
layout.Children.Add (new Label { FormattedText = formattedString });
this.Content = layout;
我在网格中有一些文本。我需要把它的一半加粗,另一半应该是正常的。我怎样才能做到?例如;
gr.Children.Add(new Label
{
Text = $"Min. Adet : {data}",
TextColor = Color.FromHex("#22223b"),
FontSize = 16
}, 3, 3);
我需要将 bold = "Min. Adet : " 和 "{data}" 设为正常。我怎样才能做到?感谢您的帮助!!!
使用Span and FormattedText
var layout = new StackLayout{ Padding = new Thickness (5, 10) };
...
var formattedString = new FormattedString ();
formattedString.Spans.Add (new Span{ Text = "Red bold, ", ForegroundColor = Color.Red, FontAttributes = FontAttributes.Bold });
var span = new Span { Text = "default, " };
span.GestureRecognizers.Add(new TapGestureRecognizer { Command = new Command(async () => await DisplayAlert("Tapped", "This is a tapped Span.", "OK")) });
formattedString.Spans.Add(span);
formattedString.Spans.Add (new Span { Text = "italic small.", FontAttributes = FontAttributes.Italic, FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)) });
layout.Children.Add (new Label { FormattedText = formattedString });
this.Content = layout;