Nov 102011
Im letzten WPF Training wurde ich gefragt wie man den Focus mit Pfeil hoch/runter auf das vorhergehende oder nachfolgende Control setzen kann. Hier ein wenig C# Code dazu:
private void Window_KeyUp(object sender, KeyEventArgs e) { switch (e.Key) { case Key.Up: MoveFocus(FocusNavigationDirection.Previous); break; case Key.Down: MoveFocus(FocusNavigationDirection.Next); break; } } private void MoveFocus(FocusNavigationDirection direction) { UIElement focusedElement = Keyboard.FocusedElement as UIElement; if (focusedElement != null) focusedElement.MoveFocus(new TraversalRequest(direction)); } |
Download: MoveFocus