2

I have this:

<Label Text="{Binding Height}" AbsoluteLayout.LayoutBounds=".9,.17,-1,-1" TextColor="White" AbsoluteLayout.LayoutFlags="PositionProportional" HorizontalTextAlignment="Center" HorizontalOptions="Center" FontSize="Medium"/>

Obviously {Binding Height} takes up the entire text.

The binding is currently a double, and needs to remain so, I just need to concat an 'm' at the end to represent meters.

I have tried {Binding Height} m and {Binding Height + m} but obviously xaml doesn't work the same way a regular string concatenation would work.

2 Answers2

4

Try using StringFormat. Like this:

Text="{Binding Height, StringFormat='{}{0}m'}"

Edited for clarity:

You can write anything you want after the {0} argument.

For example, the above will produce values like 25m, 10m etc.

You can write something like this if you like:

Text="{Binding Height, StringFormat='{}{0} is a good number.'}"

The above will produce, for example:

10 is a good number.
bolkay
  • 1,881
  • 9
  • 20
  • This worked perfectly! Thanks. How would I add spacing though? I tried simply adding a space between <...}m'> changing it to. <...} m'> but that didn't work... it still printed with no space. – iOS Developer Dec 10 '20 at 16:50
  • Hi, I edited my answer. Let me know if that answers your question. – bolkay Dec 10 '20 at 16:55
  • Perfect, thanks. Maybe I just had to clean my program then. it didn't read the space. I did however do another line for weight and entered kg instead of m, and it worked perfectly. – iOS Developer Dec 10 '20 at 16:59
0

Have you tried StringFormat?

<Label Text="{Binding Height, StringFormat={0}m}"
Jacob
  • 346
  • 3
  • 13