我有一个要在 DataGrid 中显示的客户对象列表。我通过后面的代码绑定了列表:
dataGrid.DataContext = customers;
每个客户都有一个或多个电话号码。我想在客户的行/记录中列出它们。我该怎么做呢?我的 DataGrid 在 XAML 中看起来像这样:
<DataGrid AutoGenerateColumns="False" Height="212" IsReadOnly="True"
HorizontalAlignment="Left" Margin="12,41,0,0" ItemsSource="{Binding}"
Name="dataGrid" VerticalAlignment="Top" Width="932">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Path=LastName}" Header="Porting ID"/>
<DataGridTextColumn Binding="{Binding Path=FirstName}" Header="Operator" />
</DataGrid.Columns>
</DataGrid>
客户类是:
public class Customer
{
public String LastName { get; set; }
public String FirstName { get; set; }
public List<Phonenumber> PhoneNumbers { get; set; }
}
PhoneNumber 类是:
public class PhoneNumber
{
public String AreaCode {get;set;}
public String Number {get;set;}
}