【问题标题】:How to Bind Two Lists to Two Columns of Wpf DataGrid?如何将两个列表绑定到 Wpf DataGrid 的两列?
【发布时间】:2010-05-25 20:15:17
【问题描述】:

我想将两个列表绑定到 Wpf DataGrid 的两列。这是如何在 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

【问题讨论】:

    标签: wpf datagrid binding


    【解决方案1】:

    你没有。您创建一个新列表,将两个列表中的数据合并为一个,并将合并后的列表用作数据网格的源。

    【讨论】:

      【解决方案2】:

      Zip他们:

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

      XAML

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

      【讨论】:

        猜你喜欢
        • 2014-05-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-12-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多