CoreWindow KeyDown equivalent in AppWindow #1720
-
Hi, Can anyone point me to what is the equivalent of Window.Current.CoreWindow.KeyDown in Microsoft.UI.Windowing.AppWindow? We are porting a UWP app to Windows App SDK. To detect KeyDown, we used to do this: Window.Current.CoreWindow.KeyDown -= CoreWindow_KeyDown; May I know what is the equivalent now in Windows App SDK? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Supposing you have a Grid/StackPanel or similar as the first element of the window content, I suppose you can do something like mainGrid.KeyDown += mainGrid.KeyDownHandler; |
Beta Was this translation helpful? Give feedback.
-
@martibravo Thank you for your suggestion. I tried this, somehow when mainGrid loses focus, for example if we click on a child element or another element, the KeyDown event no longer triggers, this is even when I try to click back/focus on mainGrid. I hope I am not missing anything. |
Beta Was this translation helpful? Give feedback.
-
adding a focus on PointerEntered seems to do the trick. mainGrid.Focus(FocusState.Keyboard); Thanks @martibravo |
Beta Was this translation helpful? Give feedback.
Supposing you have a Grid/StackPanel or similar as the first element of the window content, I suppose you can do something like