tags:

views:

55

answers:

1

Hello everyone, I'm trying to create a simple textblock control and I'm trying to insert a property from my ViewModel in the middle of the string.

E.G. "Hello, My name is XX, bla, bla." (XX is a property from my ViewModel)

<TextBlock Text="Hello, My name is {Binding SelectedUser.Name}, bla, bla." />

Is that possible?

Regards,

Adrian

+2  A: 

Similar feature has been added to WPF with .NET 3.5 sp1, but not to Slverlight

See Link: WPF 3.5 SP1 Feature: String Format

WPF Example:

<TextBlock 
     Text={Binding SelectedUser.Name, StringFormat=Hello, My name is: \{0\}, bla, bla.}/>

As far as Silverlight is concerned, you are stuck to either creating another property in your view model that does the concatenation for you, or creating an IValueConverter

Alex Blokh
Hello, I tryied with Silverlight 4 and FWK 3.5 and works fine!Thank you for your help.Adrian
AdrianDN
Great, I am not on SL4 yet :(Thanks for the heads up.
Alex Blokh