How to Concatenate Strings Using Binding in Silverlight

I wonder if there is a way to match two strings in Silverlight inside a xaml file. I have a DataGrid where one of the columns is "Default Contact" and I would like to represent the data there as first and last name.

<sdk:DataGridTextColumn Header="Default Contact"
                        Binding="{Binding Path=DefaultContact.FirstName}" />

      

I was thinking about something like:

Binding="{Binding Path=DefaultContact.FirstName + " " + DefaultContact.LasttName}"

      

But it doesn't work. I don't even know if this can be achieved. It looks like this is really the main thing, so I hope it is supported in some way.

Any help would be greatly appreciated.

+2


a source to share


2 answers


You can use DataGridTemplateColumn and have both your first and last name in the template. Something like that:



 <sdk:DataGridTemplateColumn Header="Name">
            <sdk:DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                        <TextBlock Padding="5,0,5,0"
                            Text="{Binding DefaultContact.FirstName}"/>
                        <TextBlock Text="{Binding DefaultContact.LastName}"/>
                    </StackPanel>
                </DataTemplate>
            </sdk:DataGridTemplateColumn.CellTemplate> 
 </sdk:DataGridTemplateColumn>

      

+5


a source


  • create field in DefaultContact

    DisplayName and concatenation is
  • Create ValueConverter

    (check MSDN)


+2


a source







All Articles