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

RibbonView is taking focus when Escape is pressed

3 Answers 151 Views
RibbonView and RibbonWindow
This is a migrated thread and some comments may be shown as answers.
BENN
Top achievements
Rank 1
BENN asked on 28 Jun 2016, 09:08 AM

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
                    Keyboard.Focus(this.Ribbon.SelectedTab);
#endif
                    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">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
 
        <telerik:RadRibbonView Name="MainRibbon" HelpButtonVisibility="Visible" HelpCommand="{Binding ShellHelpFileCommand}" GotKeyboardFocus="MainRibbon_GotKeyboardFocus"
            ApplicationName="Bob"
            telerik:KeyTipService.IsKeyTipsEnabled="True"
            MinimizeButtonVisibility="Visible"
            Foreground="Black"
            IsBackstageOpen="false"
            IsMinimized="False">
            <telerik:RadRibbonView.Backstage>
                <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:RadRibbonBackstage>
            </telerik:RadRibbonView.Backstage>
            <telerik:RadRibbonTab Foreground="Black" Header="Edit" telerik:KeyTipService.AccessText="E">
                <telerik:RadRibbonGroup Header="Clipboard" telerik:ScreenTip.Title="Clipboard"
                    telerik:ScreenTip.Description="Bla Bla"
                    telerik:KeyTipService.AccessText="FO">
                    <telerik:RadRibbonGroup.Variants>
                        <telerik:GroupVariant Variant="Medium" Priority="0"/>
                    </telerik:RadRibbonGroup.Variants>
 
                    <StackPanel Orientation="Horizontal">
                        <telerik:RadRibbonButton Text="Paste"
                            Size="Large"
                            telerik:ScreenTip.Title="Paste"
                            Click="RadRibbonButton_Click"
                            telerik:ScreenTip.Description="Paste"
                            telerik:KeyTipService.AccessText="V">
 
                        </telerik:RadRibbonButton>
                    </StackPanel>
                </telerik:RadRibbonGroup>>
            </telerik:RadRibbonTab>
        </telerik:RadRibbonView>
 
        <Grid Grid.Row="1">
            <TextBox  Width="100" VerticalAlignment="Top" HorizontalAlignment="Left"/>
        </Grid>
    </Grid>
</telerik:RadRibbonWindow>

 

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.

 

Thanks

 

3 Answers, 1 is accepted

Sort by
0
BENN
Top achievements
Rank 1
answered on 29 Jun 2016, 04:51 AM

Hi,

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?

 

Thanks

0
Accepted
Dinko | Tech Support Engineer
Telerik team
answered on 01 Jul 2016, 07:57 AM
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.

Regards,
Dinko
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
BENN
Top achievements
Rank 1
answered on 04 Jul 2016, 04:51 AM
Thanks, that seems to do the trick.
Tags
RibbonView and RibbonWindow
Asked by
BENN
Top achievements
Rank 1
Answers by
BENN
Top achievements
Rank 1
Dinko | Tech Support Engineer
Telerik team
Share this question
or