如何更改此XAML代码来对齐行和添加头? [英] How to change this XAML code to align rows and add headers?

查看:515
本文介绍了如何更改此XAML代码来对齐行和添加头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用


更新(解决有关使用DataGrid的建议): br>
问题是关于如何以类似TreeView的方式破解格式化...



DataGrid允许折叠/扩展集合的部分或者做主/细节视图,但是我找不到如何抑制重复的值,即在这种情况下是OrderName:

 订单名称部件名称数量
订单1 Part11 11
订单1 Part12 12

订单2 Part21 22
订单2 Part22 22
订单2 Part23 23


解决方案

它被称为分组,看看





它很好地解释了它。基本上你必须将你的集合包装在ListCollectionView中并定义GroupDescription。希望这有帮助!

  ListCollectionView collection = new ListCollectionView(myOrders); 
collection.GroupDescriptions.Add(new PropertyGroupDescription(OrderName);
DataGrid.ItemSource = collection;


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

  1. how to place OrderName in one line with the first line of PartNmae and PartQuantity?

  2. how to add common headers on top of columns?

That is in place of current

I'd like to produce:

Order Name       Part Name  Quantity  
Order1           Part11     11  
                 Part12     12  

Order2           Part21     22 
                 Part22     22  
                 Part23     23  

Related question based on the same code example:

Update (addressing advise about using DataGrid):
The question was about how to hack the formatting in case in TreeView-like manner...

DataGrid permits to collapse/expand parts of the collection or make master/detail views but I could not find how to suppress repeating values, i.e. in this case of OrderName:

Order Name       Part Name  Quantity  
Order1           Part11     11  
Order1           Part12     12  

Order2           Part21     22 
Order2           Part22     22  
Order2           Part23     23  

解决方案

It is called grouping and have a look at

It explains it pretty nicely. Basically you have to wrap your collection in a ListCollectionView and define the GroupDescription. Hope this helps!

ListCollectionView collection = new ListCollectionView(myOrders);
collection.GroupDescriptions.Add(new PropertyGroupDescription(OrderName);
DataGrid.ItemSource = collection;

这篇关于如何更改此XAML代码来对齐行和添加头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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