Is there any way to do this in a binding expression:
Text="Hello {Binding CurrentUser}"
ie:
<TextBlock HorizontalAlignment="Right" Foreground="#3163AB" Margin="0,0,0,5"
FontWeight="Bold" Text="Hello {Binding CurrentUser}" />
Obviously I could break it out into two separate textblocks, but this would be much nicer.
As of .NET 4, the Text
property of a Run
can be bound. I use it all the time:
<TextBlock>
Hello
<Run Text="{Binding CurrentUser}" />,
how are you?
</TextBlock>
The StringFormat method is nice, but using a Run with a binding allows the use of Value Converters.
You're looking for the StringFormat
property of Binding
.
Text="{Binding CurrentUser, StringFormat=Hello {0}}"
Text="{Binding CurrentUser, StringFormat=Hello {0}}"
should do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With