Hi, we're going to start using the XamTreeGrid in our Project but we need a specific feature and since I couldn't find it in samples I thought I'd ask here. What we need to achieve is the opportunity to switch the representation of the items in the grid from normal hierarchical tree to "flat" list so that the "parents" and the "children" are on the same level sorted alphabetically. As a sample of this representation here is a screenshot of Process Explorer which can do exactly what we want: Best regards,Daniel
Hello Daniel,
Currently, the XamTreeGrid does not support any sort of built-in functionality to have this "flat" view that you are looking for, but I have been looking a bit further into it, and I believe I know of a way this could be implemented on your end. You could remove all indentation from the XamTreeGrid's layouts to get this flat look, but the sorting would not work in the way that you would like, as the sort would happen on a parent to child basis, and not so much a full grid one.
Most of the behavior to implement this would need to happen on your data item, and I would recommend adding a pair of child collections here. One collection would be for your actual hierarchical child data, which you wouldn't show in the XamTreeGrid originally, and another would be for DummyChildData that you could fill with a dummy data item to indicate that a particular record should have children, and this will allow the record to be expandable. I would then recommend a Style for DataRecordPresenter that includes a DataTrigger that checks for whether a particular child record is a dummy one or not, and you could have a bool property or flag that designates this on your data item. If the record is a dummy record, you can set the Height and Width of that DataRecordPresenter to 0. Such a style could look like the following:
<Style TargetType="{x:Type ig:DataRecordPresenter}"> <Style.Triggers> <DataTrigger Binding="{Binding DataItem.IsDummy}" Value="True"> <Setter Property="Height" Value="0"/> <Setter Property="Width" Value="0"/> </DataTrigger> </Style.Triggers> </Style>
At this point, you have a system where the records that have children will be expandable, but only the dummy record will be shown and then it will be hidden, but on the data item exists the actual child items. This is where the RecordExpanded and RecordCollapsed events of the XamTreeGrid come in. These events will allow you to get the exact record that was expanded or collapsed, get the data item from that particular record, and then add it to the parent-level data source of the XamTreeGrid and refresh the record sort on expansion. Conversely, this will allow you to remove those same records on collapse of a particular record. The code for this would look like the following, where vm.Data is the collection bound to the grid:
DataRecord record = e.Record as DataRecord;SampleData sd = record.DataItem as SampleData;
foreach(SampleData child in sd.ActualChildData){ vm.Data.Add(child);}
((XamTreeGrid)sender).Records.RefreshSort();
There are a couple of restrictions to get this to work, such as the need to manually generate the FieldLayouts in your XamTreeGrid, as you will need to point it at the dummy child record collection. Each of your actual child data items and your parent data items will need to be of the same type as well, because to get this to work, they will all need to have the ability to be added to the same collection.
I have attached a sample project to demonstrate the above. I hope this helps you.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer