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

编程入门 行业动态 更新时间:2024-10-28 03:18:19
本文介绍了将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数据网格绑定到多个数据源

本文发布于:2023-11-12 23:27:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582803.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   数据源   网格   绑定   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!