I have the following hierarchy in WPF:
Window > Grid > ScrollViewer > StackPanel > [UserControl1, UserControl2 …]
Now I would like to receive key press events in StackPanel as soon as the window is in focus. How do I accomplish this? Merely, adding code to PreviewKeyUp/Down handlers in StackPanel doesn’t seem to work; looks like these events aren’t tunneled from the Window through the StackPanel.
Should I be looking at RoutedEventHandlers?
Edit: What I noticed was, that the key events are received if the stack panel has focus. Otherwise, it doesn’t.
Try this;
add it to application startup.