Reputation: 1733
I need to display Time inside a Li.e. '20 min'. My data is stored as integer so 'min' should be appended. Is there a way to append a default string 'min' to my bound value?
Upvotes: 0
Views: 1128
Reputation: 69979
You can simply use the Binding.StringFormat
property to format or append additional information to your data bound value:
<TextBlock Text="{Binding Time, StringFormat={}{0} min}" />
When Time
has a value of 25
, this renders like so:
You can also try using '
marks, but you'll have to leave an initial space:
<TextBlock Text="{Binding Time, StringFormat=' {0} min'}" />
UPDATE >>>
Thanks to @Krishna for the following information:
To use the string format with a Label
control, you must use the ContentStringFormat
property instead:
<Label Content="{Binding Time}" ContentStringFormat="{}{0} min}" />
Upvotes: 2
Reputation: 1996
You can use Run
like below
<TextBlock><Run Text="{Binding Time}"/><Run Text=" min"/></TextBlock>
Upvotes: 4