Phil Gan
Phil Gan

Reputation: 2863

How do I change the font on the bound part of a TextBlock's content?

Given the below TextBlock, how do I make the SomeString part of the text bold?

 <TextBlock Text="{Binding SomeString,StringFormat='{}Row: {0}'}" />

ie: If SomeString = "ABC" I want the TextBlock to look like this:

Row: ABC

Upvotes: 1

Views: 149

Answers (2)

biju
biju

Reputation: 18040

Try something like this

    <StackPanel Orientation="Horizontal">
        <TextBlock Text="Row:"/>
        <TextBlock FontWeight="Bold" Text="{Binding SomeString}"/>
    </StackPanel>

Upvotes: 2

Karthik Mahalingam
Karthik Mahalingam

Reputation: 1071

Basically, you could format each individual Run inside the same TextBlock.

Through XAML

<TextBlock>
        <Run>Row:</Run>
        <Run FontWeight="Bold" Text="{Binding SomeString}"></Run>
</TextBlock>

MSDN Section

Hope this helps.

Upvotes: 2

Related Questions