user1472131
user1472131

Reputation: 421

Bind TextBlock text when it is more then a simple string

I have a textblock and I would like to bind its content to a property in my viewmodel. This is fine if the content is a simple string. But it's no so fine if I want to format the content and use or tags... In this case I cannot bind a string: the textblock would simply display a string like this "Hallo".

Any ideas ? Thanks

Upvotes: 0

Views: 147

Answers (3)

Clemens
Clemens

Reputation: 128062

See what the StringFormat property can do for you. If that is not sufficient, you might want to write a binding converter.

Upvotes: 1

TMan
TMan

Reputation: 4122

Something like this:

  <Textblock content="{Binding MyProperty, StringFormat={}Hello {1}}" />

Just got to play with the string format.

Upvotes: 0

blindmeis
blindmeis

Reputation: 22435

if you have a property of some type - you can create a datatemplate for this type

<DataTemplate DataType="{x:Type local:MySomeType}">
  <!--your visual presentation goes here-->
</DataTemplate>

now you can simply use a ContentPresenter to show your property

 <ContentPresenter Content="{Binding MySomeTypeProperty}"/>

Upvotes: 1

Related Questions