将WPF数据网格绑定到多个数据源 [英] Bind a WPF data grid to multiple data sources

查看:313
本文介绍了将WPF数据网格绑定到多个数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在WPF中创建了一个数据网格,有2个列表。我想绑定一列到一个列表,其余的列绑定到另一个列表。
任何人都可以告诉我怎么做?



谢谢

解决方案

基本上,你不能。 datagrid是一个ItemsControl,它具有一个ItemsSource属性。



我会做的是构建一个视图模型,它是一个包含每个项目之一的复合对象(从两个列表)。那么你可以绑定到这些的集合。

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


I have created a data grid in WPF and have 2 lists. 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.

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; }
}

这篇关于将WPF数据网格绑定到多个数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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