How to concatenate strings in Xamarin.Forms?
Use FormattedText
property in xamarin forms Label
as follow:
<Label Grid.Column="1" Grid.Row="1">
<Label.FormattedText>
<FormattedString>
<Span TextColor="White" FontSize="18" Text="{Binding EMP_LAST_NAME'}"/>
<Span TextColor="White" FontSize="18" Text="{Binding EMP_FIRST_NAME}"/>
</FormattedString>
</Label.FormattedText>
</Label>
Xamarin.Forms Label
And also you can add Style
to avoid code duplication for TextColor
, FontSize
and other properties in your code.
Styling Xamarin.Forms Apps using XAML Styles
You can't bind to multiple properties on a View
Element
.
In this case you should create a new property which does the format you want and bind it to the View
.
Example:
public class EmployeeViewModel
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string FullName => $"{FirstName} {LastName}";
}
Then in XAML
:
<Label Text="{Binding FullName}"/>
Another approach:
As suggested in the comments we can also use FormattedText
property in a Label
:
<Label.FormattedText>
<FormattedString>
<Span Text="{Binding FirstName}" />
<Span Text="{Binding LastName}"/>
</FormattedString>
</Label.FormattedText>