WPF,如何使文本在字符串中变为粗体 [英] WPF, How to make text as bold in a string

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

问题描述

我有一个WPF应用程序. Introtext有一个键,例如"My name is John".来自静态资源文件"EmployeeResources.resx".

我想将字符串显示为我的名字约翰". (必须为粗体),如下文所述.

<b; StackPanel Orientation =垂直"; Grid.Column ="2">
                < TextBlock Text =" {x:静态名称:EmployeeResources.Introtext}" />
 </StackPanel>

我如何实现这一目标.

解决方案

要在TextBlock中获取格式,您需要类似以下内容:

< TextBlock>
            <运行>我的名字</运行>
            < Run FontWeight =粗体"; Text ="{Binding the Iss""</Run>
            < Run> John</Run>
        </TextBlock>

您将需要分解您的文本,以便"Run"(运行).可以为每个具有不同FontWeight(或其他Font属性)的零件创建.


I have a WPF application. There is a key as Introtext as "My name is John" which is coming from the static resource file "EmployeeResources.resx".

I want to display string as "My name is John" (Is must be bold) in a SINGLE textblock as mention below. 

 <StackPanel Orientation="Vertical" Grid.Column="2">
                <TextBlock Text="{x:Static name:EmployeeResources.Introtext}" />
 </StackPanel>

How can I achieve this. 

解决方案

To get formatting in a TextBlock you need something like:

        <TextBlock>
            <Run>My Name</Run>
            <Run FontWeight="Bold" Text="{Binding theIs}"></Run> 
            <Run>John</Run>
        </TextBlock>

You will need to decompose your text so that a "Run" can be created for each part that has a different FontWeight (or other Font properties).


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

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