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

5

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>
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.