开发者

How to do Inline text formatting?

For example if I have this:

string message = "The Quick Brown Fox";    
someTextBlock.Text = message;

it will 开发者_C百科show by default like this:

The Quick Brown Fox

How to I make it show up in a TextBlock (or any element with content)?

Like this: The Quick Brown Fox

Note:

By "inline" I am refering to how this is done in HTML:

someDiv.InnerHtml = "The <b>Quick</b> Brown <b>Fox</b>";


It is better to do it in XAML like this:

<TextBlock>
    The <Bold>Quick</Bold> Brown <Bold>Fox</Bold> 
</TextBlock>

But you also can do it in code via Inlines property of TextBlock:

someTextBlock.Inlines.Add(new Run() { Text = "The " });
someTextBlock.Inlines.Add(new Run() { Text = "Quick ",  FontWeight = FontWeights.Bold });
someTextBlock.Inlines.Add(new Run() { Text = "Brown " });
someTextBlock.Inlines.Add(new Run() { Text = "Fox",  FontWeight = FontWeights.Bold });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜