如何在Silverlight中加粗静态字符串 [英] How to Bold a static string in silverlight

查看:118
本文介绍了如何在Silverlight中加粗静态字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

如何使静态字符串加粗...

我的任务..........

Hi Guys,

How to make a static string Bold...

My Task..........

TextBlock textblock = new TextBlock();
textblock.Text = "Display Metrics:";
textblock.FontWeight = FontWeights.Bold;
String str=textblock.Text;
mystackpanel.Children.Add(textblock);



现在,文本块具有显示指标"文本,该文本为粗体,如何将这种粗体文本复制到字符串str.



Now textblock has a "Display Metrics" text which is bold, how to copy this bold text to a String str.

推荐答案

.NET中的String类保存Unicode字符序列.它不包含任何格式信息.

尼克
The String class in .NET holds a sequence of Unicode characters. It does not hold any formatting information.

Nick


您可以将值保存为XML格式.您可以将Text保存到元素,也可以将FontWeight保存到属性.从textblock中获取它们.

另外,由于TextBlocks可以包含具有多种格式的文本,因此您可能需要研究TextBlock.Inlines,这将有助于获得创建的TextBlocks格式,如下所示:
You could save the values in an XML format. You could save Text to an element and you could save FontWeight to an attribute. Get them both from textblock.

Also, since TextBlocks can contain text with a variety of formatting, you might want to look into TextBlock.Inlines, which will help get the formatting of TextBlocks created like so:
<TextBlock Name="tb1">
    This has some <Bold>bold</Bold> text.
</TextBlock>


您可以尝试使用富文本框来显示文本.

这样,您可以复制RTF格式,然后粘贴到另一个RTF框中.
You could try using a rich text box to display text.

This way you can copy the rich text format and then paste in another rich text box.


这篇关于如何在Silverlight中加粗静态字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆