Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 886
user1060500 Avatar asked Jan 29 '26 06:01

user1060500


1 Answers

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}

like image 113
H.B. Avatar answered Jan 30 '26 21:01

H.B.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!