Escape Key and ToolWindow

4 posts, 0 answers
  1. James
    James avatar
    136 posts
    Member since:
    Nov 2008

    Posted 06 Aug 2010 Link to this post

    Hello,

    Is it possible to close a ToolWindow with the Escape Key?

    I have been able to achieve this if another control has focus inside the ToolWindow, but if no control is in focus then the KeyDown event is never fired.

    Help appreciated,

    Regards
    James.
  2. George
    Admin
    George avatar
    1332 posts

    Posted 10 Aug 2010 Link to this post

    Hello James,

     
    KeyDown event fires when the sender has the focus. If it is not selected, it won't fire.

    Please do not hesitate to contact us if you require any further information.


    Regards,
    George
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. James
    James avatar
    136 posts
    Member since:
    Nov 2008

    Posted 11 Aug 2010 Link to this post

    Ok thanks for that.

    Are you saying it is not possible to close a ToolWindow with the Escape Key?

    If it is possible, can you please provide code to achieve this.

    Regards,

    James.
  5. George
    Admin
    George avatar
    1332 posts

    Posted 16 Aug 2010 Link to this post

    Hello James,

    No, it is not impossible. Here is the code to accomplish this:  

    public partial class MainPage : UserControl
       {
           RadWindow window;
           public MainPage()
           {
               InitializeComponent();
               this.KeyDown += new KeyEventHandler(UserControl_KeyDown);
               this.window = new RadWindow();
               this.window.Content = new TextBlock { Text = "Press esc to close the window" };
               this.window.Show();
           }
     
           private void UserControl_KeyDown(object sender, KeyEventArgs e)
           {
               if (e.Key == Key.Escape)
               {
                   this.window.Close();
               }
           }
       }

    You could handle KeyDown event for the MainPage - just make sure the focus in on the MainPage UserControl.

    I hope this helps! 

    Best wishes,
    George
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top