In the new Ag 3 applic...">

Silverlight Canvas not support KeyDown?

I have it:

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

In the new Ag 3 application in VS2008. I simply changed the default <Grid /> to <Canvas /> and added the KeyDown handler that appears in the MessageBox.

But no matter how hard I try, the KeyDown simply never fires.

Is it just that <Canvas /> does not support KeyDown , or am I doing something wrong?

+4
source share
2 answers

You should have at least something inside the Canvas that can get focus, and you will find that the event will bubble.

You can also set IsHitTestVisible="True" on the canvas.

+4
source

Since your Canvas is a "LayoutRoot", you can use UserControl instead.

Put the IsTabStop="true" property in the UserControl . In the Loaded event this.Focus() . Attach the KeyDown handler to UserControl instead of Canvas .

As long as the plugin itself has focus (which you can provide with a little Javascript), you should get key events.

+3
source

Source: https://habr.com/ru/post/1306301/


All Articles