RibbonView is taking focus when Escape is pressed

4 posts, 1 answers
  1. BENN
    BENN avatar
    62 posts
    Member since:
    Dec 2011

    Posted 28 Jun 2016 Link to this post

    We use a custom autocomplete textbox, and it's been working fine with Telerik Controls from 2012.

    We've recently upgraded the DLL, and I've noticed that there is a new problem. When the Autocomplete is focused and Escape is being pressed, the textbox still has logical focus, but the keyboard focus is lost (The cursor is still on the textbox, but it is not blinking anymore).

    After debugging it, I've found out that KeyTipService.HandleEscape is being called, and this specific code takes the keyboard focus:

                    if (this.Ribbon != null)
    #if WPF
                        if (this.Ribbon.IsBackstageOpen)
                            this.Ribbon.IsBackstageOpen = false;


    I've tested this issue on a test project, and I can reproduce the issue, even with a regular textbox:

    <telerik:RadRibbonWindow x:Class="RibbonTakesFocusFromAutoComplete.MainWindow"
            Title="MainWindow" Height="350" Width="525">
        <Grid x:Name="contentToDisable">
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            <telerik:RadRibbonView Name="MainRibbon" HelpButtonVisibility="Visible" HelpCommand="{Binding ShellHelpFileCommand}" GotKeyboardFocus="MainRibbon_GotKeyboardFocus"
                    <telerik:RadRibbonBackstage telerik:KeyTipService.AccessText="F">
                        <telerik:RadRibbonBackstageItem Header="New" telerik:KeyTipService.AccessText="N" Click="RadRibbonBackstageItem_Click" />
                        <telerik:RadRibbonBackstageItem Header="Open" telerik:KeyTipService.AccessText="O" Click="RadRibbonBackstageItem_Click_1"/>
                <telerik:RadRibbonTab Foreground="Black" Header="Edit" telerik:KeyTipService.AccessText="E">
                    <telerik:RadRibbonGroup Header="Clipboard" telerik:ScreenTip.Title="Clipboard"
                        telerik:ScreenTip.Description="Bla Bla"
                            <telerik:GroupVariant Variant="Medium" Priority="0"/>
                        <StackPanel Orientation="Horizontal">
                            <telerik:RadRibbonButton Text="Paste"
            <Grid Grid.Row="1">
                <TextBox  Width="100" VerticalAlignment="Top" HorizontalAlignment="Left"/>


    Run the project, and click the TextBox so it will get keyboard focus. Press the Escape key, and you'll see what I mean.

    Is there any workaround?


    Can you please fix it.




  2. BENN
    BENN avatar
    62 posts
    Member since:
    Dec 2011

    Posted 28 Jun 2016 Link to this post


    I forgot to mention that in the HandleEscape code, it checks that the current focused element is a TextBox, and only then it does the rest of the code I've posted.


    To me, it looks like a bug, and I think that this code should have been executed only if the TextBox is a child of the ribbon.

    I think that this code is related to the code in the ActivateKeyTips function:

    private bool ActivateKeyTips(KeyEventArgs args, bool hasTips)
        var textBox = args.OriginalSource as TextBox;
        this.isKeyboardNavigationActive = false;
        if (textBox != null)
            if (textBox.ParentOfType<RadRibbonView>() != null || textBox.ParentOfType<RadRibbonBackstage>() != null)
                return false;
      // More code here

    The key tips does not open if a TextBox inside the ribbon (This is used for example for the "Font Family" or "Font Size" RadRibbonComboBox which contains a TextBox).


    Am I right about my assumption? If there any workaround other than fixing it myself (until patched by you), and recompiling the sources?



  3. Answer
    Dinko avatar
    462 posts

    Posted 01 Jul 2016 Link to this post

    Hi Benn,

    Thank you for the provided detail information. 

    We can confirm that this is a bug and therefore we logged it in our Feedback Portal. This way you can track its progress and vote for its implementation. We have also updated your Telerik points for bringing this issue to our attention.

    A possible workaround which you can try is to subscribe to the KeyUp event of the window and handle the EscapeKey if the RibbonView is not focused. You can use the IsAncestorOf() method to check if the focused element is a child of the RadRibbonView and if yes you can handle the event.
    void MainWindow_PreviewKeyUp(object sender, KeyEventArgs e)
        var isAncestor = this.MainRibbon.IsAncestorOf(Keyboard.FocusedElement as FrameworkElement);
        if (e.Key == Key.Escape && !isAncestor)
            e.Handled = true;

    Give it a try and let me know if this works for you.

    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  4. BENN
    BENN avatar
    62 posts
    Member since:
    Dec 2011

    Posted 03 Jul 2016 Link to this post

    Thanks, that seems to do the trick.
Back to Top