开发者

How to do Inline text formatting?

开发者 https://www.devze.com 2023-03-08 13:57 出处:网络
For example if I have this: string message = \"The Quick Brown Fox\"; someTextBlock.Text = message; it will 开发者_C百科show by default like this:

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

精彩评论

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