Ctrl+w,上移
Ctrl+s,下移
AddHandler(Keyboard.KeyDownEvent, (KeyEventHandler)HandleKeyDownEvent);
private void HandleKeyDownEvent(object sender, KeyEventArgs e)
{
if (e.Key == Key.W && (Keyboard.Modifiers & (ModifierKeys.Control)) == (ModifierKeys.Control))
{
if (datagrid.SelectedIndex <= 0)
{
datagrid.SelectedIndex = 0;
}
else
{
datagrid.SelectedIndex = datagrid.SelectedIndex - 1;
}
}
else if (e.Key == Key.S && (Keyboard.Modifiers & (ModifierKeys.Control)) == (ModifierKeys.Control))
{
if (datagrid.SelectedIndex == datagrid.Items.Count - 1)
{
datagrid.SelectedIndex = datagrid.Items.Count - 1;
}
else
{
datagrid.SelectedIndex = datagrid.SelectedIndex + 1;
}
}
}