Handle WPF Image control's KeyUP and KeyDown won't work, we have to put the KeyUp & KeyDown handler at the window level.
<Window x:Class="WPFImageControl.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" KeyDown="Window_KeyDown" KeyUp="Window_KeyUp">
<Grid>
<Image x:Name="image1" Source="build.png" />
</Grid>
</Window>
Code Behind:
private void Window_KeyDown(object sender, KeyEventArgs e)
{
Debug.WriteLine("Window KeyDown: " + e.Key + " Time:" +DateTime.Now.ToString());
}
private void Window_KeyUp(object sender, KeyEventArgs e)
{
Debug.WriteLine("Window KeyUp: " + e.Key + " Time:" + DateTime.Now.ToString());
}