开发者

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

开发者 https://www.devze.com 2023-01-01 13:32 出处:网络
I want to bind two lists to two columns of a Wpf DataGrid. How is this done in Xaml? Class MainWindow

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}
    Publi开发者_如何学运维c Property Column2 As List(Of Integer) = New List(Of Integer) From {4, 5, 6}

End Class


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.


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}" />
...
0

精彩评论

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