Event handled not working in KeyDown event?

4 posts, 0 answers
  1. hvduc
    hvduc avatar
    33 posts
    Member since:
    Jun 2010

    Posted 17 Apr 2013 Link to this post

    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?
  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 22 Apr 2013 Link to this post

    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.

  3. DevCraft banner
  4. hvduc
    hvduc avatar
    33 posts
    Member since:
    Jun 2010

    Posted 22 Apr 2013 Link to this post

    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?
  5. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 25 Apr 2013 Link to this post

    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.

Back to Top