<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}" KeyDown="Grid_KeyDown">
<Image HorizontalAlignment="Left" Height="285" Margin="187,128,0,0" VerticalAlignment="Top" Width="328"
Source="ms-appx:///Assets/Logo.png" KeyDown="Image_KeyDown"/>
<TextBox HorizontalAlignment="Left" Margin="76,46,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Height="82" Width="195"
KeyDown="TextBox_KeyDown"/>
</Grid>
private void Image_KeyDown(object sender, KeyRoutedEventArgs e)
{
int i = 9;
}
private void TextBox_KeyDown(object sender, KeyRoutedEventArgs e)
{
int i = 9;
}
private void Grid_KeyDown(object sender, KeyRoutedEventArgs e)
{
int i = 9;
}
过程: 如果你让TextBox首先获得焦点:然后点击键盘,Debug时候断点会先进入
private void TextBox_KeyDown(object sender, KeyRoutedEventArgs e)
{
int i = 9;
}
然后再进入
private void Grid_KeyDown(object sender, KeyRoutedEventArgs e)
{
int i = 9;
}
不过不会进入 private void Image_KeyDown(object sender, KeyRoutedEventArgs e)
如果TextBox失去焦点,此时点击键盘Image上的Grid_KeyDown与Image_KeyDown事件都不会触发;
Image控件并不能获得输入焦点,无法响应KeyDown KeyUp,Image上的KeyDown事件一直不被触发
分析过程中的Grid上的KeyDown事件产生响应是因为路由事件
应该解释的比较详细了