CodeGo.net>如何做内联文本格式?
作者:互联网
例如,如果我有这个:
string message = "The Quick Brown Fox";
someTextBlock.Text = message;
它将默认显示为:
The Quick Brown Fox
如何使它显示在TextBlock(或任何具有内容的元素)中?
像这样:Quick Brown Fox
注意:
通过“内联”,我指的是如何在HTML中完成此操作:
someDiv.InnerHtml = "The <b>Quick</b> Brown <b>Fox</b>";
解决方法:
最好在XAML中这样做:
<TextBlock>
The <Bold>Quick</Bold> Brown <Bold>Fox</Bold>
</TextBlock>
但是您也可以通过TextBlock的Inlines属性在代码中执行此操作:
someTextBlock.Inlines.Add(new Run() { Text = "The " });
someTextBlock.Inlines.Add(new Run() { Text = "Quick ", FontWeight = FontWeights.Bold });
someTextBlock.Inlines.Add(new Run() { Text = "Brown " });
someTextBlock.Inlines.Add(new Run() { Text = "Fox", FontWeight = FontWeights.Bold });
标签:silverlight-4-0,c,silverlight 来源: https://codeday.me/bug/20191102/1992582.html