Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StringFormat with Font Weight

Tags:

wpf

I'm using StringFormat to show some bound data and works fine.

<TextBlock>
    <TextBlock.Text>
        <MultiBinding StringFormat="Name {0} | Id ({1})">
          <Binding Path="Name" />
          <Binding Path="Id"/>
        </MultiBinding>
    </TextBlock.Text>
</TextBlock>

I want the Id value (see XAML) to be bold. How to do this?

like image 276
Stacked Avatar asked Jun 10 '13 08:06

Stacked


1 Answers

Use Run (and/or Bold) elements inside the TextBlock instead of it's Text property, you can bind and style them separately.

e.g.

<TextBlock>
    <Run Text="Name "/><Run Text="{Binding Name}"/>
    <Run Text=" | "/>
    <Run Text="Id ("/><Run Text="{Binding Id}" FontWeight="Bold"/><Run Text=")"/>
</TextBlock>

alternatively to <Run Text="{Binding Id}" FontWeight="Bold"/>:

<Bold><Run Text="{Binding Id}"/></Bold>
like image 162
H.B. Avatar answered Sep 29 '22 11:09

H.B.