WPF TextBlock格式 [英] WPF TextBlock formatting
本文介绍了WPF TextBlock格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我是WPF的新手。我正在使用WPF中的usercontrols,我在usercontrol中有一个TextBlock。
我的格式化字符串来自我的Web服务,格式如下。 />
Hi All,
I am a newbie to WPF. I am working on the usercontrols in WPF where in I have a TextBlock in usercontrol.
I have a formatted string coming from my web service in the following format.
This is <Bold>Sample</Bold>, <Italic>Text</Italic>
我需要将此文本设置为用户控件的TextBlock。
当我这样设置时,wpf屏幕上的输出正如预期的那样。
I need to set this text to the TextBlock of my user control.
When I set it like this, the output on the wpf screen comes as expected.
<TextBlock Height="181" HorizontalAlignment="Left" Margin="71,33,0,0" Name="textBlock1" VerticalAlignment="Top" Width="316">
Test with <Bold>bold</Bold>, <Italic>italic</Italic> and
</TextBlock>
如何通过代码设置TextBlock的内嵌文本?
提前致谢。
快乐编码
推荐答案
请阅读此链接 http://msdn.microsoft.com/en-us/library/system.windows.controls.textblock(V = vs.110)的.aspx [ ^ ]
样本:
pls read this link http://msdn.microsoft.com/en-us/library/system.windows.controls.textblock(v=vs.110).aspx[^]
sample:
textBlock1.Inlines.Add(new Bold(new Run("bold")));
............
textBlock1.Inlines.Add(new Italic(new Run("italic")));
参考 - 基本HTML标记在WPF TextBlock中 [ ^ ]。
建议使用......
Refer - Basic HTML Markup in WPF TextBlock[^].
It suggests to use...
textBlock.Inlines.AddRange(SierraLib.UI.WPF.Text.MarkupProcessor.HTMLtoWPF("<b><u><i>Show me some text!</i></u></b>"));
所以,你需要替换< Bold> < b> 和< Italic>在此代码之前的< i> 。
这篇关于WPF TextBlock格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文