I try to use XamDataGrid with a collection of items of the class Foo as the :
class Foo { public int Id { get; set; } public string Name { get; set; } public ObserervableCollection<Foo> Children { get; set; } }
For top-level items of Foo and children of Foo items, they use the same field layout.
I don't want to maintain two field layouts (one for top-level items and one for children) as there is lots of programmatic customization based on external data. It's messy enough doing it once, and the required synchronization to keep all the columns in line is burdensome.
It looks like I should be able to restyle the DataRecordPresenter, but I can't figure out how to get it to work as the only properly on HeaderRecord that has any information about its nested level is internal to the class AttachedNestingLevel (if I remember right).
Even so, I mucked about with reflection to use that value and while I can detect the header, I was never able to hide the data record. My guess is the DataRecordPResenter is just too complex for my old mind to get figured out.
How can I restyle the Data Record Presenter to hide the redundant column header for children items?
The highlighted row is what I want to hide: in the real app:
Hello Douglas,
There is a setting that allows you to hide or show headers by assigning a FieldLayoutSettings object to the FieldLayout.Settings property and setting the LabelLocation property, like so:
<ig:FieldLayout> <ig:FieldLayout.Settings> <ig:FieldLayoutSettings LabelLocation="Hidden" /> </ig:FieldLayout.Settings> </ig:FieldLayout>
The problem with your scenario and why the style is necessary is because the FieldLayout is shared in your case, and so this would hide all headers. If you were using multiple FieldLayouts, the above is my recommendation.
Please let me know if you have any other questions or concerns on this matter.
Great!
the trick for me was setting the height to zero... visibility set to collapsed should do this also, but I guess the header row visibility logic is more extensive and not so easy to override.
Would be a nice feature to add to FieldLayout is a flag to show/hide child row headers as needed.
I have been investigating into a way to hide the headers of different child bands if you are using the same FieldLayout in this case, and the best recommendation I have for you is to have something in your underlying data that will designate the records as children or not. This could be as simple as a bool property, and it does not have to be shown in the XamDataGrid to be bound to.
If you do this, you can utilize a MultiDataTrigger in a Style for DataRecordPresenter that binds to two conditions. The first is the RecordType of the underlying record and whether this is a HeaderRecord. The second would be utilizing the property mentioned above, as you could bind to AttachedToRecord.DataItem.<your_property_name_here>. If these conditions pass, you can set the Height property to 0, as the Visibility will be resolved.
I am attaching a sample project to demonstrate this.
It is also worth noting that we have a separate grid – the XamTreeGrid that does this by default and expects data in the structure that you are passing. It has all of the features of the XamDataGrid, and so perhaps that control would better suit your needs in this case?
XDGHideHeadersDemo.zip