如何将两个列表绑定到两列Wpf DataGrid? [英] How to Bind Two Lists to Two Columns of Wpf DataGrid?

查看:247
本文介绍了如何将两个列表绑定到两列Wpf DataGrid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将两个列表绑定到Wpf DataGrid的两列。如何在Xaml中完成?

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


推荐答案

Zip 他们:

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

XAML

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

这篇关于如何将两个列表绑定到两列Wpf DataGrid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆