I'm trying to create a custom editor for a XamDataGrid using an adorning layer, where below a normal textbox is a helper which allows the user to select from one of a few selections specific to the column.
For the most part it works but one of the things I need it to do is that when the user uses up and down arrows, those are used to move through the items of the XamGrid in the adorner. I can only get that to work by setting focus to the XamGrid, which takes the original Field out of edit mode (which I do not want).
Is there a way to modify this or a better way than using an adorning layer?
My sample project, building off of Brian Lagunas' framework:
https://drive.google.com/file/d/0B4uNoNzjY3SJSXo4V0I4NVNWaWc/view?usp=sharing
Hello Walter,
I have been investigating into the sample project that you have provided me, and I would recommend against setting focus to the XamGrid in your adorner if you are looking to keep the XamDataGrid cell in edit mode in this case. The adorner layer that you have created is in the same focus and visual scope as the XamDataGrid in this case, and so by focusing the XamGrid instead, you will exit edit mode on the cell. If the XamGrid were to be in a different visual tree or focus scope, it is possible that you could be able to prevent this behavior.
My recommendation instead, is to handle the Key.Down and Key.Up presses yourself in the ProcessKeyStroke method of your AttributeLevelCellAdorner class, and mark the corresponding XamGrid Row selected with each key-stroke rather than trying to focus the grid. Marking a row selected in the XamGrid will not actually focus it, and so you will get the visual cue that something is happening with the XamGrid adorner without losing edit mode in the XamDataGrid. You can access the selected rows in the XamGrid by throttling the XamGrid.SelectionSettings.SelectedRows collection. Each Row that you can select has an Index property, and so if you check this index, you can move the selected row accordingly.
At this point, you can have a check for the "commit" buttons, such as a check for Key.Enter, and obtain the underlying data item from the Row element that is selected in your XamGrid. This Row element has a Data property that returns the underlying data item, and using it, you should be able to push the underlying value of your cell back to the XamDataGrid.
I have attached a modified version of the sample project you sent 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