开发者

Way to concat strings when using binding in Silverlight

开发者 https://www.devze.com 2022-12-27 16:11 出处:网络
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 fi

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:

Bindi开发者_如何学JAVAng="{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.


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>


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

精彩评论

暂无评论...
验证码 换一张
取 消