Bind a WPF data grid to multiple data sources

孤街醉人 提交于 2019-12-07 13:13:23

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/3010473/bind-a-wpf-data-grid-to-multiple-data-sources

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!