Canvas不支持KeyDown

Canvas不支持KeyDown

本文介绍了Silverlight Canvas不支持KeyDown?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个:

<Canvas x:Name="LayoutRoot" KeyDown="LayoutRoot_KeyDown">
</Canvas>

在VS2008中新建的Ag 3应用程序中。我只是将默认的< Grid /> 更改为< Canvas /> 并添加了一个 KeyDown 弹出MessageBox的处理程序。

In a newly-minted Ag 3 application in VS2008. I simply changed the default <Grid /> to <Canvas /> and added a KeyDown handler that pops a MessageBox.

但无论我如何尝试, KeyDown 事件只会永远不会被触发。

But no matter how I tried, the KeyDown event just would never, ever fires.

只是< Canvas /> 不支持 KeyDown 或者我做错了什么?

Is it simply that <Canvas /> doesn't support KeyDown or am I doing something wrong?

推荐答案

您需要至少拥有可以接收焦点的内容,您会发现事件将会起泡。

You need to have at least something inside the Canvas that can receive focus, and you will find that the event will bubble up.

您可能还想设置 IsHitTestVisible =True在画布上。

You may also want to set IsHitTestVisible="True" on the Canvas.

这篇关于Silverlight Canvas不支持KeyDown?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 15:50