Search code examples
.netwpfxamldata-bindingtextblock

Adding text to a bound TextBlock


I would like to prepend a text in a data-bound text block:

<TextBlock Text="{Binding Title}" />

The text that is shown is:

"My title"

What I want to be shown is:

This is "My title"

Solution

  • You can use the StringFormat property of the binding:

     <TextBlock Text="{Binding Title, StringFormat=This is {0}}"></TextBlock> 
    

    Check out this blog post for more information: WPF String.Format in XAML with the StringFormat attribute.