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

Event handled not working in KeyDown event?

3 Answers 345 Views
MaskedInput (Numeric, DateTime, Text, Currency)
This is a migrated thread and some comments may be shown as answers.
hvduc
Top achievements
Rank 1
hvduc asked on 17 Apr 2013, 09:35 AM
Hi Telerik,
I'm using Telerik controls for Silverlight 2013.1.220.1050.
I handle KeyDown event for RadMaskedCurrencyInput and set e.Handled = True when Tab key is pressed but it's not working (next control is still focused).
Is this a bug or I need to set a property that I don't know to handle this event?

3 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 22 Apr 2013, 06:21 AM
Hi hvduc,

Usually preventing the normal action of a button should be done in Preview events, for example PreviewKeyDown, handling the KeyDown won't work in your scenario. Unfortunately, PreviewKeyDown is only available in WPF. In Silverlight, you have to inherit from RadMaskedCurrencyInput and override the OnKeyDown method to achieve similar effect.

Kind regards,
Petar Mladenov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
hvduc
Top achievements
Rank 1
answered on 22 Apr 2013, 07:44 AM
Hi Telerik,
I tried overrided OnKeyDown method like you mentioned but it's not working.
In OnKeyDown method, when e.Key = Key.Tab, I set e.Handled = True but my cursor's still focus next control.
Is there other way to stop KeyDown event?
0
Petar Mladenov
Telerik team
answered on 25 Apr 2013, 06:52 AM
Hi hvduc,

 You can find possible approach in the attached project. I subscribe for the KeyDown event of the Stackpanel which holds MaskedInput and TextBox. I check whether the original source is the currency input (the textbox in its controltemplate) and whether the pressed key is Tab. Let us know if this helps you move forward.

private void StackPanel_KeyDown(object sender, KeyEventArgs e)
        {
            bool isMaskOriginalSource = e.OriginalSource is Telerik.Windows.Controls.MaskedInput.PreviewInputTextBox;
            if (e.Key == Key.Tab && isMaskOriginalSource)
            {
                e.Handled = true;
            }
        }


Greetings,
Petar Mladenov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
MaskedInput (Numeric, DateTime, Text, Currency)
Asked by
hvduc
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
hvduc
Top achievements
Rank 1
Share this question
or