public FormattedString FormattedDescription
{
get
{
return new FormattedString
{
Spans =
{
new Span
{
Text = RoleName,
FontSize = 16,
FontAttributes = FontAttributes.Bold
},
new Span
{
Text = "/ " + ProjectRoleID + "/ "+Part + "/ "+Gender + "/ " + AgeRange
},
}
};
}
set
{
}
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,我想在第一行显示RoleName,在第二行显示其他详细信息.
Dam*_*mer 45
这是一个完全在 XAML 中的“清洁”解决方案:
xmlns:system="clr-namespace:System;assembly=netstandard"这是系统命名空间,它包含所有系统类。
<Label>
<Label.FormattedText>
<FormattedString>
<Span Text="First Text"/>
<Span Text=" "/>
<Span Text="Second Text"/>
<Span Text="{x:Static system:Environment.NewLine}"/>
<Span Text="Above is a new line"/>
</FormattedString>
</Label.FormattedText>
</Label>
Run Code Online (Sandbox Code Playgroud)
在这里,您有一种干净的方式来显示新行。
您可以使用Environment.NewLine将文本移动到下一行,如下所示:
public FormattedString FormattedDescription
{
get
{
return new FormattedString
{
Spans = {
new Span { Text = RoleName, FontSize = 16, FontAttributes = FontAttributes.Bold },
new Span { Text = Environment.NewLine, FontSize = 16 },
new Span { Text = "/ " + ProjectRoleID + "/ "+Part + "/ "+Gender + "/ " + AgeRange},
}
};
}
set { }
}
Run Code Online (Sandbox Code Playgroud)
您还可以使用 XAML 属性元素语法来执行此操作:
<Label>
<Label.FormattedText>
<FormattedString>
<Span>
<Span.Text>
Line 1
Line 2
</Span.Text>
</Span>
</FormattedString>
</Label.FormattedText>
</Label>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5121 次 |
| 最近记录: |