是否可以在Xamarin.Forms Label小部件中使用粗体和非粗体文本?是否有可能在标签内部有终结点?
<Label Text="Abc <b>def</b>"/> <Label Text="Abc \ndef"/>
最好的方法是绑定FormattedText样式,如下所示:
<Label FormattedText="{Binding CustomFormattedText}" />
在模型中:
public FormattedString CustomFormattedText { get { return new FormattedString { Spans = { new Span { Text = Sum, FontAttributes=FontAttributes.Italic, FontSize="10" }, new Span { Text = Info, FontSize="10" } } }; } set { } }
看看the documentation中的 FormattedString .
FormattedString
您创建一个 FormattedString 对象,该对象由多个 Span 对象组成,这些对象都可以拥有自己的字体,重量,颜色等 .
Span
例:
var labelFormatted = new Label (); var fs = new FormattedString (); fs.Spans.Add (new Span { Text="Red, ", ForegroundColor = Color.Red, FontSize = 20, FontAttributes = FontAttributes.Italic) }); fs.Spans.Add (new Span { Text=" blue, ", ForegroundColor = Color.Blue, FontSize = 32) }); fs.Spans.Add (new Span { Text=" and green!", ForegroundColor = Color.Green, FontSize = 12) }); labelFormatted.FormattedText = fs;
关于新行, \n 应该有效 . 另一种解决方法是这样做:
\n
<Label> <Label.Text> This is my magical unicorn text </Label.Text> </Label>
2 回答
最好的方法是绑定FormattedText样式,如下所示:
在模型中:
看看the documentation中的
FormattedString
.您创建一个
FormattedString
对象,该对象由多个Span
对象组成,这些对象都可以拥有自己的字体,重量,颜色等 .例:
关于新行,
\n
应该有效 . 另一种解决方法是这样做: