How to concatenate strings in Xamarin.Forms?

I want my two lines to be split into one line. Is it possible that it would look like this:

Curry stephen

using this code

Text = "{Binding EMP_LAST_NAME + EMP_FIRST_NAME}" ??

I currently have this code. Many thanks.

<ListView ItemsSource="{Binding EmployeesList}"
        HasUnevenRows="True">
<ListView.ItemTemplate>
  <DataTemplate>
    <ViewCell>
      <Grid Padding="10" RowSpacing="10" ColumnSpacing="5">
        <Grid.RowDefinitions>
          <RowDefinition Height="Auto"/>
          <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="Auto"/>
          <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>

        <controls:CircleImage Source="icon.png"
               HeightRequest="66"
               HorizontalOptions="CenterAndExpand"
               Aspect="AspectFill"
               WidthRequest="66"
               Grid.RowSpan="2"
               />

        <Label Grid.Column="1"
              Grid.Row="1"
              Text="{Binding EMP_LAST_NAME}"
               TextColor="White"
               FontSize="18"
               Opacity="0.6"/>

        <Label Grid.Column="1"
              Grid.Row="1"
              Text="{Binding EMP_FIRST_NAME}"
               TextColor="White"
               FontSize="18"
               Opacity="0.6"/>



      </Grid>
    </ViewCell>
  </DataTemplate>
</ListView.ItemTemplate>

+4
source share
2 answers

You cannot bind to multiple properties in View Element.

In this case, you must create a new property that makes the desired format, and bind it to View.

Example:

public class Employee
{
    public string FirstName { get; set; }    
    public string LastName { get; set; }    
    public string FullName => string.Format("{0} {1}", FirstName, LastName);
}

Then in XAML:

<Label Text="{Binding FullName}"/>
+8
source

IValueConverter, Employee .

MultiComponentLabel. Label.

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Name="Page"
             xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:controls="clr-namespace:SuperForms.Controls;assembly=SuperForms.Controls"
             x:Class="SuperForms.Samples.MultiComponentLabelPage">
  <controls:MultiComponentLabel Margin="0,20,0,0">
    <controls:MultiComponentLabel.Components>
      <controls:TextComponent Text="{Binding EMP_LAST_NAME}"/>
      <controls:TextComponent Text="{Binding EMP_FIRST_NAME}"/>
    </controls:MultiComponentLabel.Components>
  </controls:MultiComponentLabel>
</ContentPage>

MultiComponentLabel Label s

ListView

<ListView ItemsSource="{Binding EmployeesList}"
    HasUnevenRows="True">
<ListView.ItemTemplate>
  <DataTemplate>
    <ViewCell>
      <Grid Padding="10" RowSpacing="10" ColumnSpacing="5">
        <Grid.RowDefinitions>
          <RowDefinition Height="Auto"/>
          <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="Auto"/>
          <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>

    <controls:CircleImage Source="icon.png"
           HeightRequest="66"
           HorizontalOptions="CenterAndExpand"
           Aspect="AspectFill"
           WidthRequest="66"
           Grid.RowSpan="2"
           />

    <controls:MultiComponentLabel Grid.Row="1" Grid.Column="1">
    <controls:MultiComponentLabel.Components>
      <controls:TextComponent Text="{Binding EMP_LAST_NAME}"/>
      <controls:TextComponent Text="{Binding EMP_FIRST_NAME}"/>
    </controls:MultiComponentLabel.Components>
  </controls:MultiComponentLabel>



  </Grid>
</ViewCell>

+4

All Articles