Search code examples
c#wpftextbindingtextblock

Add text to TextBlock Text property when it's binded


I have a TextBlock where its Text property is binded with another property that rappresents a value:

<TextBlock Text="{Binding Path=Count}" FontWeight="Bold" />

So, if (for example) Count is 4, I'll see in my TextBlock the number 4.

Now, what I have to do if I want to add some text before and after the number 4 (for example I'd like to see that number in square brackets [4])?

Thanks.


Solution

  • You sould use stringformat

    <TextBlock Text="{Binding Path=Count, StringFormat={}[{0}]}" FontWeight="Bold" />