I have a scenario where I want to show hierarchical data in a DataGrid in Silverlight 3 while having the header rows still have the standard set of cells and being editable. The user needs to be able to collapse and expand rows to hide child rows.
I've accomplished this by having a button on each parent row that looks like either a collapse or an expand glyph depending on its state. Clicking this manipulates a property on the data item for its child rows. Each row has its visibility bound to this property of the data item.
This works somewhat decently, though it does have performance problems with the grid rendering more columns than it needs to.
My problem now is that when the user hits up or down on the keyboard they are able to navigate to hidden rows.
For example if I have a structure like
1 Parent (Expanded, Visible)
1a (Visible)
1b (Visible)
2 Parent (Collapsed, Visible)
2a (Hidden)
3 Parent (Expanded, Visible)
3a (Visible)
If I have [2 Parent] selected and I hit the down arrow on the keyboard I would expect the selection to go to [3 Parent] but it goes to [2a] instead even though [2a]'s row visibility is set to Visibility.Collapsed.
I'd like to be able to either intercept the keyboard event (via something like the non-existent PreviewKeyDown event) and handle it myself or to find some way of tricking the DataGrid's internals of moving to the correct item.
At this point I am fairly invested in tweaking the row visibility for hiding these items.
Any ideas?