简体   繁体   English

将WPF数据网格绑定到多个数据源

[英]Bind a WPF data grid to multiple data sources

I have created a data grid in WPF and have 2 lists. 我在WPF中创建了一个数据网格,并有2个列表。 I want to bind one column to one list and rest of the columns to another list. 我想将一列绑定到一个列表,将其余列绑定到另一个列表。 Can anyone please tell me how to do this? 谁能告诉我怎么做?

Thanks 谢谢

Basically, You cant. 基本上,你不能。 The datagrid is an ItemsControl which has one ItemsSource property. datagrid是一个ItemsControl,它有一个ItemsSource属性。

What i would do is build a view model which is a composite object that contains one of each of the items (from the two lists). 我要做的是构建一个视图模型,它是一个复合对象,包含每个项目之一(来自两个列表)。 then you could bind to a collection of these. 然后你可以绑定到这些的集合。

public class CompositeItem{
   public Object ItemFromListOne { get; set; }
   public Object ItemFromListTwo { get; set; }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM