You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to make a Grid respond to KeyDown but is perplexed by the behavior.
In the following, KeyDown function of the Grid does not trigger.
Adding a Button, KeyDown function starts to trigger.
Clicking on anywhere of the Grid (not on the Button) causes the KeyDown to stop triggering.
Clicking back on the button (bringing Focus), makes the KeyDown starts triggering again.
If I just want my Grid with a simple background color without any children to respond to KeyDown, what is the correct way to do it? Or am I missing something above? Thanks in advance.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I am trying to make a Grid respond to KeyDown but is perplexed by the behavior.
If I just want my Grid with a simple background color without any children to respond to KeyDown, what is the correct way to do it? Or am I missing something above? Thanks in advance.
<Window
x:Class="App1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
>
<Grid x:Name="mainGrid" KeyDown="Grid_KeyDown" Background="Blue">
<!--
<Button x:Name="Hello" Click="Hello_Click">Test
-->
</Grid>
</Window>
Code Behind
Windows 11 with Windows App SDK 1 Preview 3
Beta Was this translation helpful? Give feedback.
All reactions