Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate String with Bindings XAML

Is it possible to have some static text and a bindable context in the same label?

<Label Text = "${Binding totalCost}"
       x:Name = "totalCost"
       HorizontalOptions = "Start"
       VerticalOptions = "Start"
       Grid.Row = "6" Grid.Column = "1"/>

Except this displays as "${Binding totalCost}"

I know I could just easily set the field by doing something like totalCost.Text = String.Format("${0}", totalCost); but just wanted to see if it was possible the other way

like image 779
John Avatar asked May 16 '16 18:05

John


2 Answers

See if this works for you:

Text="{Binding totalCost, StringFormat=${0}}"
like image 158
15ee8f99-57ff-4f92-890c-b56153 Avatar answered Oct 30 '22 10:10

15ee8f99-57ff-4f92-890c-b56153


For labels there is additional feature: ContentStringFormat, example bellow:

<Label Content="{Binding Tag, FallbackValue=Custom}" ContentStringFormat="Length: {0}" DataContext="{Binding ElementName=cbRebarLength, Path=SelectedItem}"/>
like image 40
Paulius Vasiliauskas Avatar answered Oct 30 '22 10:10

Paulius Vasiliauskas