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

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

问题描述

我要两个列表绑定到一个WPF DataGrid中的两列。这是如何在XAML中做了什么?

 类主窗口    公共属性列1作为表(整数)=新名单(整数)从{1,2,3}
    公共属性列2方式列表(整数)=新名单(整数)从{4,5,6}末级


解决方案

邮编其中:

  dataGrid1.ItemsSource =列1 _
                        .ZIP(列2,_
                             功能(C1,C2)新借助{.Column1 = C1,.Column2 = C2})

XAML

  ...
< D​​ataGridTextColumn绑定={绑定列1}/>
< D​​ataGridTextColumn绑定={绑定列2}/>
...

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

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天全站免登陆