It really bothers me that the pressing the enter key in a Datagrid moves the selection down one item, I'd like to be able to decide what it does in a normal keydown event.
So what I did was create a new class that inherits DataGrid and override the OnKeyDown event and use that as my datagrid.
This creates a whole new set of problems, since I apparently have to rewrite all the other keypresses (arrow key navigation, shift+arrow key selection, pgup/pgdn, etc..). I've been trying to hack it, but it just seems so pointless spending time rewriting something that has already been written and probably better then whatever I'll come up with.
So how can I make the enter key do what I want without messing with the other default keybindings of the datagrid?
Thanks in advance
You will need to bind a PreviewKeyDown
handler to the Datagrid and then manually check whether the key value is Key.Enter
.
If yes, set e.Handled = true
.
Just check if the key pressed is enter, if it's not, call the base event handler for KeyDown (something like base.OnKeyDown(sender, args);
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With