user1060500
user1060500

Reputation: 1535

Best Practice for Inline binding with XAML and text Text="Some text {Some binding} some more text}"

I'm wondering if there is special syntax to bind text concatenated with existing text.

Something like this.

<TextBlock Grid.Row="0" Name="tbGroupMembershipCaption"
           Text="The following users have access to export to '{Binding TargetName}'."/>

Clearly, this doesn't work.

What is the best practice?

Using SL4.

Upvotes: 2

Views: 1893

Answers (4)

Bruno
Bruno

Reputation: 563

This is what worked for me. Close to the last one but that one would not work for me.

<TextBlock HorizontalAlignment="Right" Grid.Column="2" Grid.Row="1" Text="{Binding       CreatedBy, StringFormat=By \{0\}}"/>

Upvotes: 0

brunnerh
brunnerh

Reputation: 185225

Use StringFormat on the Binding.

WPF: {Binding SomeProp, StringFormat={}Head text {0} Tail text}
WPF/SL: {Binding SomeProp, StringFormat='{}Head text {0} Tail text'}
WPF/SL Alt.: {Binding SomeProp, StringFormat=Head text \{0\} Tail text}

Upvotes: 8

devdigital
devdigital

Reputation: 34359

Text="{Binding TargetName, StringFormat=The following users have access to export to \{0\}}"

See http://msdn.microsoft.com/en-us/library/system.windows.data.bindingbase.stringformat.aspx for more details.

Upvotes: 3

Joel B Fant
Joel B Fant

Reputation: 24766

Perhaps this:

Text="{Binding TargetName, StringFormat=The following users have access to export to '\{0\}'."

Upvotes: 1

Related Questions