2010-05-25 78 views
1

我想将两个列表绑定到Wpf DataGrid的两列。 Xaml如何完成这项工作?如何将两个列表绑定到Wpf DataGrid的两列?

Class MainWindow 

    Public Property Column1 As List(Of Integer) = New List(Of Integer) From {1, 2, 3} 
    Public Property Column2 As List(Of Integer) = New List(Of Integer) From {4, 5, 6} 

End Class 

回答

1

Zip他们:

dataGrid1.ItemsSource = Column1 _ 
         .Zip(Column2, _ 
          Function(c1, c2) New With { .Column1 = c1, .Column2 = c2 }) 

XAML

... 
<DataGridTextColumn Binding="{Binding Column1}" /> 
<DataGridTextColumn Binding="{Binding Column2}" /> 
... 
2

你不知道。您创建一个新列表,将两个列表中的数据合并为一个列表,并使用合并列表作为数据网格的源。