什么是最简单的XAML代码数据绑定这种化合物(集合)对象(WPF)? [英] What would be the simplest XAML code to databind this compound (collection) object (WPF)?

查看:162
本文介绍了什么是最简单的XAML代码数据绑定这种化合物(集合)对象(WPF)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码这个WPF应用程序(或什么是相同的,的这个),一个数据绑定集合а(List对象(myOrders):




  1. 什么是更简单的
    (最简单的可能)XAML脚本这样的结合,即绑定集合对象?


  2. <基于相同的代码示例p>相关问题:结果
    如何改变这一XAML代码对齐行和添加页眉?



解决方案

您可以预测你的指令集到零件征收,哪知道其父为了一个ViewModel类包装的每个元素,如果它要在订单名称显示其标签。collumn与否
这将是这样的(我没有测试!):

 公共类PartWrapper {
酒店的公共部件部件{搞定;设置;}
治安秩序得到{;设置;}
公共BOOL ShowOrder {搞定;设置;}

公共PartWrapper(部分部分,订货订单,布尔showOrder){
this.Part =一部分;
this.Order =秩序;
this.ShowOrder = showOrder;
}
}

VAR项目= this.orders.SelectMany(O => o.Parts.Select(P =>新建PartWrapper(P,O,FALSE) )).ToList();
的foreach(在items.GroupBy(VAR我项目= GT; i.Order)。选择(G => g.First()))
item.ShowOrder = TRUE;


Taking the code of this WPF application (or what is the same, this), databinding a а collection (List object (myOrders):

  1. What would be more simple (the simplest possible) XAML script for such binding, i.e. to bind a collection object?

  2. Related question based on the same code example:
    How to change this XAML code to align rows and add headers?

解决方案

You could project your Order collection into a Part collection, wrapping each element in a ViewModel class which knows its parent order and if it should display its label in the "Order name" collumn or not. It would be something like (I have not tested!):

public class PartWrapper{
    public Part Part{ get; set;}
    public Order Order{ get; set;}
    public bool ShowOrder{ get; set;}

    public PartWrapper(Part part, Order order, bool showOrder){
        this.Part = part;
        this.Order = order;
        this.ShowOrder = showOrder;
    }
}

var items = this.orders.SelectMany(o => o.Parts.Select(p => new PartWrapper(p, o, false)) ).ToList();
foreach(var item in items.GroupBy(i => i.Order).Select(g => g.First()))
    item.ShowOrder = true;

这篇关于什么是最简单的XAML代码数据绑定这种化合物(集合)对象(WPF)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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