#244 – 使用TextBlock显示多种多样的格式文本(Use a TextBlock Element for Richer Formatting)

Label控件支持设置字体大小、粗细等属性,但是这些设置会应用到Label所有的文本上。它很难嵌入不同格式的字符。

TextBlock 控件允许通过添加不同的Run 元素来格式化其一部分显示的文本。不同的Run 格式化的内容可以不尽相同。

下面是Label的例子:

<Label Background="DarkGray" Margin="10" Height="50" FontSize="14"
    Content="Lancaster / York Richard, Duke of York Henry VI Warwick Somerset" />

下面是TextBlock 的例子,显示不同的内容

<TextBlock Background="DarkGray" Margin="10" Height="100" FontSize="14">
    <Run Text="Lancaster" Foreground="Red" TextDecorations="Underline"/><Run Text=" / "/>
    <Run Text="York" Foreground="White" TextDecorations="Underline"/>
    <LineBreak/>
    <Run Text="Richard, Duke of York" Foreground="White" FontSize="16" FontWeight="Bold"/>
    <LineBreak/>
    <Run Text="Henry VI" Foreground="Red" FontSize="16" FontWeight="Bold"/>
    <LineBreak/>
    <Run Text="Warwick" Foreground="White" FontStyle="Italic"/>
    <LineBreak/>
    <Run Text="Somerset" Foreground="Red" FontStyle="Italic"/>
</TextBlock>

下面是效果:


原文地址:https://wpf.2000things.com/2011/03/13/244-use-a-textblock-element-for-richer-formatting/

********************************************译者注**********************************************

可以看到TextBlock通过Run可以显示十分丰富的内容格式。

不仅仅是颜色、下划线、字体等,包含下标、上标、注脚等格式都可以实现。

1. 下面的代码是上标的实现代码,Run中的内容会以上标的形式显示

<Run Typography.Variants="Superscript">This text is Superscripted.</Run> This text isn't.

2. 下面的代码是下标的实现代码,Run中的内容会以下标的形式显示

 <Run Typography.Variants="Subscript">This text is Subscripted.</Run> This text isn't.



on the impact of technology on society. Technology has undoubtedly revolutionized the way we live, work, and interact with each other. The advancements in technology have enabled us to achieve feats that were once deemed impossible, such as exploring space, connecting with people across the globe, and gathering vast amounts of information at lightning speed. However, these advancements have also brought about significant changes in society, some of which are not entirely positive. One of the most significant impacts of technology on society is the widening gap between the haves and have-nots. As technology becomes more sophisticated, it becomes increasingly expensive, making it inaccessible to those who cannot afford it. This has led to an increase in income inequality, where the rich get richer, and the poor get poorer. Another impact of technology on society is the loss of jobs. With the rise of automation and artificial intelligence, machines are increasingly taking over jobs that were once done by humans. While this has led to increased efficiency and productivity, it has also resulted in job losses, particularly in industries such as manufacturing and retail. The impact of technology on society is not all negative, however. Technology has also brought about significant improvements in healthcare, education, and communication. Medical advancements have enabled us to treat and cure diseases that were once considered fatal, while online education has made learning accessible to people all over the world. Communication has also been revolutionized, with social media platforms enabling us to connect with people from different cultures and backgrounds. In conclusion, the impact of technology on society is complex and multifaceted. While it has brought about significant improvements in many areas, it has also created new challenges and problems. As we continue to advance technologically, it is essential that we consider the social and ethical implications of these advancements, and work towards creating a more equitable and just society.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值