2016-07-05 5 views
4

2つの文字列を1行に表示します。このコードXamarin.Formsで文字列を連結する方法は?

テキスト= "{バインディングEMP_LAST_NAME + EMP_FIRST_NAME}"を使用して

カレースティーブン

:それはこのように表示されすることが可能ですか? ? ?

私は現在このコードを持っています。どうもありがとう。

<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> 

答えて

8

あなたはViewElement上の複数のプロパティにバインドすることはできません。

この場合は、希望する書式で新しいプロパティを作成し、Viewにバインドする必要があります。

例:XAMLで次に

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

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

私は卿の背後にあるコードでそれを行う必要がありますあなたのために代わりに夫婦のMultiComponentLabelを使うのか?どうやって? –

+0

私の編集された答えを見てください。 – jzeferino

4

あなたはEmployeeを受け入れるとフルネームを返しますIValueConverterを、使用することができます。

またはMultiComponentLabelを使用できます。それは1つの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> 

だけLabel

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> 

+0

XAMLでどうすればいいですか? –

+0

ListViewに適用されますか? –

+0

@JayceeEvangelistaは、あなたが 'ListView'で使ったコードを追加しました。 –

関連する問題