This is a migrated thread and some comments may be shown as answers.

Escape Key and ToolWindow

3 Answers 71 Views
Docking
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 06 Aug 2010, 10:43 AM
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.

3 Answers, 1 is accepted

Sort by
0
George
Telerik team
answered on 10 Aug 2010, 04:05 PM
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
0
James
Top achievements
Rank 1
answered on 11 Aug 2010, 09:09 AM
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.
0
George
Telerik team
answered on 16 Aug 2010, 02:10 PM
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
Tags
Docking
Asked by
James
Top achievements
Rank 1
Answers by
George
Telerik team
James
Top achievements
Rank 1
Share this question
or