views:

173

answers:

2

I wonder if there is a way of concating two strings in Silverlight inside xaml file. I have a DataGrid where one of the columns is 'Default Contact' and I would like to represent data in 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 this doesn't work. I don't even know if this is possible to achieve. Seems like really basic thing so I hope it is supported in some way.

Any help would be greatly appreciated.

+2  A: 
  1. create a field in DefaultContact called DisplayName and concatenate there
  2. Create ValueConverter (check MSDN)
Andrey
+2  A: 

You could use a DataGridTemplateColumn and have both your first and last name in the template. Something like this:

 <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>
E.Z. Hart
Thanks a million!
Artur