How to Bind Two Lists to Two Columns of Wpf DataGrid?

会有一股神秘感。 提交于 2020-01-05 05:55:34

问题


I want to bind two lists to two columns of a Wpf DataGrid. How is this done in Xaml?

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 them :

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

XAML

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



回答2:


You don't. You create a new list which merges data from the two lists into one and use the merged list as source for the datagrid.



来源:https://stackoverflow.com/questions/2908185/how-to-bind-two-lists-to-two-columns-of-wpf-datagrid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!