Vahid
Vahid

Reputation: 5454

How to use StringFormat to format a text in XAML

I'm trying to format display the following text using StringFormat in XAML, but I don't know where to enter the "Current Temperature: " string here:

<TextBlock Text="{Binding TempText, StringFormat={"Current Temperature: "}{0}°C}" 

The final output should be:

Current Temperature: 10°C

Upvotes: 0

Views: 1178

Answers (2)

Jawahar
Jawahar

Reputation: 4885

The following code gives you the required output.

<TextBlock Text="{Binding TempText, StringFormat='Current Temperature: {0} &#186; C'}"/>

Upvotes: 3

MBDevelop
MBDevelop

Reputation: 123

You may use MultiBinding along with StringFormat

this msdn may help:

"http://msdn.microsoft.com/en-us/library/system.windows.data.bindingbase.stringformat%28v=vs.110%29.aspx"

Upvotes: 0

Related Questions