如何使一部分 Stringbuilder 内容加粗? [英] How to make a part of Stringbuilder content bold?
本文介绍了如何使一部分 Stringbuilder 内容加粗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
StringBuilder sb = new StringBuilder();
sb.Append(
string.Format("{0} |{1} ", Name, Value)
);
Display.Text = sb.ToString(); // Display is a WP7 TextBlock control
我想将姓名"设为粗体.可以这样做吗?
I want to make "Name" as bold. Is it possible to do that ?
推荐答案
您需要将文本放入RichTextBox
并将名称作为单独的Run
Paragraph
如来自 MSDN 的示例所示:
You'll need to put the text into a RichTextBox
and have the name as a separate Run
in the Paragraph
as in this example from the MSDN:
// Create a Run of plain text and some bold text.
Run myRun1 = new Run();
myRun1.Text = "A RichTextBox with ";
Bold myBold = new Bold();
myBold.Inlines.Add("initial content ");
Run myRun2 = new Run();
myRun2.Text = "in it.";
// Create a paragraph and add the Run and Bold to it.
Paragraph myParagraph = new Paragraph();
myParagraph.Inlines.Add(myRun1);
myParagraph.Inlines.Add(myBold);
myParagraph.Inlines.Add(myRun2);
// Add the paragraph to the RichTextBox.
MyRTB.Blocks.Add(myParagraph);
这篇关于如何使一部分 Stringbuilder 内容加粗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文