• Upgrade your Internet Experience
  • Sign in
  • Microsoft.com
  • United States (English)
    Brasil (Português)Česká republika (Čeština)Deutschland (Deutsch)España (Español)France (Français)Italia (Italiano)Россия (Русский)대한민국 (한국어)中华人民共和国 (中文)台灣 (中文)日本 (日本語)香港特别行政區 (中文)
 
 
.NET Framework Developer Center
 
 
Home
 
 
Library
 
 
Learn
 
 
Downloads
 
 
Support
 
 
Community
 
 
Forums
 
 
 
.NET Framework Developer Center > .NET Development Forums > Windows Presentation Foundation (WPF) > Extended canvas KeyDown event not fired
Ask a questionAsk a question
Search Forums:
  • Search Windows Presentation Foundation (WPF) Forum Search Windows Presentation Foundation (WPF) Forum
  • Search All .NET Development Forums Search All .NET Development Forums
  • Search All MSDN Forums Search All MSDN Forums
 

AnswerExtended canvas KeyDown event not fired

  • Friday, May 02, 2008 5:01 PMAnonymousjtyjtyj Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0

    Hi,

     

    In my window I have tabcontainer which includes tabs with my extended canvas.

    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.

     

    Best regard

    MN

    • ReplyReply
    • QuoteQuote
     

Answers

  • Monday, May 05, 2008 4:51 AMWei Zhou - MSFTModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Vote As Helpful
    0

    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.

     

    Code Snippet

    <Canvas KeyDown="Canvas_KeyDown" PreviewKeyDown="Canvas_PreviewKeyDown"

           Focusable="True" Width="300" Height="300"/>

    private void Canvas_KeyDown(object sender, KeyEventArgs e)

    {

        Debug.WriteLine("KeyDown");

    }

    private void Canvas_PreviewKeyDown(object sender, KeyEventArgs e)

    {

        Debug.WriteLine("PreviewKeyDown");

    }

     

     

    Best Regards,

    Wei Zhou

    • ReplyReply
    • QuoteQuote
     

All Replies

  • Tuesday, May 06, 2008 7:45 AMAnonymousjtyjtyj Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0

     

    Ok it works but I moved logic of key down event at canvas container level (TabItem).

     

    Best regards

    MarN

    • ReplyReply
    • QuoteQuote
     
Need Help with Forums? (FAQ)
 
© 2009 Microsoft Corporation. All rights reserved.
Terms of Use
|
Trademarks
|
Privacy Statement