覆盖回车键,但在wpf数据网格中保留其他键的默认行为 [英] Override the enter key, but keep default behavior for other keys in a wpf datagrid

查看:76
本文介绍了覆盖回车键,但在wpf数据网格中保留其他键的默认行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确实让我感到困扰的是,在Datagrid中按下回车键会将选择项向下移动一个项目,我希望能够确定在正常的按下事件中它所做的事情.

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.

所以我要做的是创建一个新类,该类继承DataGrid并重写OnKeyDown事件并将其用作我的数据网格.

So what I did was create a new class that inherits DataGrid and override the OnKeyDown event and use that as my datagrid.

这会带来一系列全新的问题,因为我显然不得不重写所有其他按键(箭头键导航,shift +箭头键选择,pgup/pgdn等).我一直在尝试破解它,但是花时间重写已经写好的东西似乎毫无意义,而且可能比我想出的要好.

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.

那么如何在不弄乱数据网格的其他默认键绑定的情况下使enter键做我想做的事情?

So how can I make the enter key do what I want without messing with the other default keybindings of the datagrid?

预先感谢

推荐答案

只需检查是否按下了按下的键,否则,请调用KeyDown的基本事件处理程序(类似于base.OnKeyDown(sender, args);)

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);)

这篇关于覆盖回车键,但在wpf数据网格中保留其他键的默认行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆