1.变向响应Tab按键
private
void
Grid_KeyUp(
object
sender, KeyEventArgs e)
{
UIElement element = Keyboard.FocusedElement
as
UIElement;
if
(e.Key == Key.Down || e.Key == Key.Enter)
{
if
(element !=
null
)
{
element.MoveFocus(
new
TraversalRequest(FocusNavigationDirection.Next));
}
}
if
(e.Key == Key.Up)
{
if
(element !=
null
)
{
element.MoveFocus(
new
TraversalRequest(FocusNavigationDirection.Previous));
}
}
}
2.响应键盘按键,根据需求响应不同key键
控件.RaiseEvent(new KeyEventArgs(Keyboard.PrimaryDevice, Keyboard.PrimaryDevice.ActiveSource, 0, Key.Right)
{ RoutedEvent = UIElement.KeyDownEvent });