Extended canvas KeyDown event not fired<p align=left><font face=Arial size=2>Hi,</font></p> <p align=left> </p> <p align=left>In my window I have tabcontainer which includes tabs with my extended canvas.</p> <p align=left>I tried in few ways add handlers for events (KeyDown, OnPreviewKeyDown etc, AddHandler(...)) on this canvas but event is not fireing. I tried to use Keyboard.Focus method but it still not works. What should I do? I would like to add some canvas connected functionality which needs keyboard.</p> <p align=left> </p> <p align=left>Best regard </p> <p align=left>MN</p>© 2009 Microsoft Corporation. All rights reserved.Thu, 19 Jun 2008 00:15:52 Z9ce00f7a-30bc-4101-90fe-bc0c2518bc76http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/9ce00f7a-30bc-4101-90fe-bc0c2518bc76#9ce00f7a-30bc-4101-90fe-bc0c2518bc76http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/9ce00f7a-30bc-4101-90fe-bc0c2518bc76#9ce00f7a-30bc-4101-90fe-bc0c2518bc76Anonymousjtyjtyjhttp://social.msdn.microsoft.com/Profile/en-US/?user=AnonymousjtyjtyjExtended canvas KeyDown event not fired<p align=left><font face=Arial size=2>Hi,</font></p> <p align=left> </p> <p align=left>In my window I have tabcontainer which includes tabs with my extended canvas.</p> <p align=left>I tried in few ways add handlers for events (KeyDown, OnPreviewKeyDown etc, AddHandler(...)) on this canvas but event is not fireing. I tried to use Keyboard.Focus method but it still not works. What should I do? I would like to add some canvas connected functionality which needs keyboard.</p> <p align=left> </p> <p align=left>Best regard </p> <p align=left>MN</p>Fri, 02 May 2008 17:01:25 Z2008-05-06T07:46:23Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/9ce00f7a-30bc-4101-90fe-bc0c2518bc76#8bb2eb58-aa3f-452b-b6f9-6b5a0d5c1122http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/9ce00f7a-30bc-4101-90fe-bc0c2518bc76#8bb2eb58-aa3f-452b-b6f9-6b5a0d5c1122Wei Zhou - MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=Wei%20Zhou%20-%20MSFTExtended canvas KeyDown event not fired<p>This is because the Canvas control is not focusable by default. You can set the Canvas.Focusable to true to achieve this goal. Here is the example.</p> <p align=left> </p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left><span style="color:blue"> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Snippet</span></div> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left><span style="color:blue">&lt;</span><span style="color:#a31515">Canvas</span><span style="color:red"> KeyDown</span><span style="color:blue">=&quot;Canvas_KeyDown&quot;</span><span style="color:red"> PreviewKeyDown</span><span style="color:blue">=&quot;Canvas_PreviewKeyDown&quot;</span></p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left>       <span style="color:red">Focusable</span><span style="color:blue">=&quot;True&quot; </span><span style="color:red">Width</span><span style="color:blue">=&quot;300&quot;</span><span style="color:red"> Height</span><span style="color:blue">=&quot;300&quot;/&gt;</span></p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left><span style="color:blue">private</span> <span style="color:blue">void</span> Canvas_KeyDown(<span style="color:blue">object</span> sender, <span style="color:#2b91af">KeyEventArgs</span> e)</p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left>{</p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left>    <span style="color:#2b91af">Debug</span>.WriteLine(<span style="color:#a31515">&quot;KeyDown&quot;</span>);</p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left>}</p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left><span style="color:blue">private</span> <span style="color:blue">void</span> Canvas_PreviewKeyDown(<span style="color:blue">object</span> sender, <span style="color:#2b91af">KeyEventArgs</span> e)</p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left>{</p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left>    <span style="color:#2b91af">Debug</span>.WriteLine(<span style="color:#a31515">&quot;PreviewKeyDown&quot;</span>);</p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left>}</p> <p align=left> </p></div></div> <p align=left> </p></span> <p></p> <p style="font-size:9pt;background:white;margin:0px;color:black;font-family:Courier New" align=left></p> <p align=left>Best Regards,</p> <p align=left>Wei Zhou</p>Mon, 05 May 2008 04:51:47 Z2008-05-06T07:46:23Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/9ce00f7a-30bc-4101-90fe-bc0c2518bc76#65868f93-248f-4f9a-9251-57c50e118bcchttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/9ce00f7a-30bc-4101-90fe-bc0c2518bc76#65868f93-248f-4f9a-9251-57c50e118bccAnonymousjtyjtyjhttp://social.msdn.microsoft.com/Profile/en-US/?user=AnonymousjtyjtyjExtended canvas KeyDown event not fired<p align=left><font face=Arial size=2></font> </p> <p>Ok it works but I moved logic of key down event at canvas container level (TabItem).</p> <p align=left> </p> <p align=left>Best regards</p> <p align=left>MarN</p>Tue, 06 May 2008 07:45:40 Z2008-05-06T07:45:40Z