wpf : how to handle KeyDown Event for Datagrid?

2019-06-20 02:29发布

问题:

I have a problem with datagrid control in wpf . when I press enter I want to load selected items in a set of controls, but it seems that datagrid.KeyDown is already handled and it goes to the next item.

I tried using keyup but this event fires when the datagrid keydown had been fired and datagrid goes to the next item.

any idea to handle keydown completely ?

回答1:

Use the PreviewKeyDown event instead of KeyDown



回答2:

Maybe KeyDown is handled by a ClassHandler.
Instance listeners come after class listeners.

A good explanation on MSDN.