Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
226 views
in Technique[技术] by (71.8m points)

wpf - How to change this XAML code to align rows and add headers?

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

enter image description here

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  
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...