如何分配到一个文本属性运行,编程? [英] How to assign a Run to a text property, programmatically?
本文介绍了如何分配到一个文本属性运行,编程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道在XAML中我们可以做...
I know in XAML we can do...
<TextBlock FontSize="18">
This is my text <LineBreak/>
<Run FontSize="24" FontWeight="Bold">My big bold text</Run>
</TextBlock>
问题是,我怎么可以指定一个运行到一个文本(String)属性,以编程方式?
Question is, how can I assign a Run into a text (string) property, programmatically?
推荐答案
如果你看看的TextBlock
您将看到ContentProperty设置为内联
If you look at TextBlock
you will see that ContentProperty is set to Inlines
[Localizability(LocalizationCategory.Text), ContentProperty("Inlines")]
public class TextBlock : FrameworkElement, ...
这意味着你将添加内联
元素属性内联
为的TextBlock的<打开和关闭标签之间加everyting / code>。
This means that you will add Inline
elements to the property Inlines
for everyting added between the opening and closing tag of TextBlock
.
所以,C#相当于你的XAML是
So the c# equivalent to your Xaml is
TextBlock textBlock = new TextBlock();
textBlock.FontSize = 18;
textBlock.Inlines.Add("This is my text");
textBlock.Inlines.Add(new LineBreak());
Run run = new Run("My big bold text");
run.FontSize = 24;
run.FontWeight = FontWeights.Bold;
textBlock.Inlines.Add(run);
这篇关于如何分配到一个文本属性运行,编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文