RadDocking keyboard arrows

1 Answer 118 Views
Docking
Luigi
Top achievements
Rank 3
Bronze
Iron
Iron
Luigi asked on 23 Dec 2022, 09:01 AM

Hi,

I need to react to arrows keys in document host, but I discovered that arrows key, in docking, moves the focus on the various parts of docking areas: can I disable this interaction?
Thank you 

Luigi

Stenly
Telerik team
commented on 27 Dec 2022, 10:52 AM

Hello Luigi,

I have tested this scenario, however, the control present in a RadPane that is part of the DocumentHost correctly receives the keyboard input, rather than moving the focus to other parts of RadDocking. I have attached the sample project, so, could you give it a try and let me know if I am missing something of importance?

The following gif shows the result that is present on my end:

Luigi
Top achievements
Rank 3
Bronze
Iron
Iron
commented on 27 Dec 2022, 02:57 PM

Hi Stenly

Thank you for your answer.

With your sample project I can reply the situation in all the tab but the document host: if you click the right or left arrow, you resize the area. It is that the behaviour  that I want to disable.
In the document host I replaced your listbox with an image and then also in the document host I get the behaviour (note that image is not the control that I use in my application, but it has similar properties about the keyboard interaction).
Luigi

 
Stenly
Telerik team
commented on 30 Dec 2022, 02:32 PM

Would it be possible to give the PreviewLostKeyboardFocus event of RadDocking a try?

In the scenario present in the sample project, clicking on the left/right arrows will move the focus to a RadGridResizer element, which will resize the areas. With the mentioned event, you could prevent the focus from moving by handling the event if the e.NewFocus is of type RadGridResizer.

private void RadDocking_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
    if (e.NewFocus is RadGridResizer)
    {
        e.Handled = true;
    }
}
Luigi
Top achievements
Rank 3
Bronze
Iron
Iron
commented on 24 Jan 2023, 10:22 AM

Yes,

I try and I achieved what I need.

Thank you

Luigi

Dominic
Top achievements
Rank 1
commented on 14 Apr 2025, 05:53 AM

Sorry to bump this old topic, but I'm stuck in a very similar situation and the suggested solution isn't working for me.

To be precise, I'm trying to have a terminal (command line) in a docking window.
The project is based on the `VisualStudioDocking` sample in the Telerik xaml-sdk ( https://github.com/telerik/xaml-sdk/tree/master/Docking/VisualStudioDocking ) just adding a view that contains the terminal.
But when pressing the arrow keys or the tab keys for auto-complete inside the terminal, the focus instead goes to the docking layout and changes the layout.

Adding the `PreviewLostKeyboardFocus` handler to the RadDocking element doesn't seem to work. The only time this is ever called is when the terminal receives the keyboard focus.
I also tried deriving my own `CustomRadDocking` from RadDocking and overriding all PreviewKeyDown/PreviewKeyUp/etc. events.
Even if I don't call `base.OnPreviewKeyDown(e);` etc. the focus is still lost and the layout changed instead.
Only when I set `e.Handled = true` in these functions does the focus steal not happen, but that also breaks auto-complete for the terminal.

Any input on where in Telerik this behavior is even defined would be helpful.
Thank you!

Stenly
Telerik team
commented on 14 Apr 2025, 07:42 AM

Hello Dominic,

I tested the VisualStudioDocking example from our SDK Samples Browser by adding an additional RadPane, which contains an element that supports keyboard navigation (more specifically, arrow keys navigation), however, I was unable to reproduce the mentioned behavior.

With this being said, I attached the test application, so, would it be possible to modify it to reproduce the reported behavior?

Dominic
Top achievements
Rank 1
commented on 15 Apr 2025, 12:25 AM

Hello Stenly,

Thanks so much for the quick reply!
I attached your sample project updated to illustrate what I mean:

(1) I removed the non-necessary panels for clarity.
(2) added a new TerminalView to act as a wrapper for the dummy terminal.In this example, the dummy terminal is simply a button. In the actual project it's a Microsoft WPF Terminal Control, but I had trouble integrating that into the sample project (probably .NET Framework version issues) and the button seems to show the same behavior.
(3) if you click the button, it gets keyboard focus, and by typing you can change its text. So far so good.
(4) but when pressing the keyboard's right-arrow or left-arrow, the button won't receive the key event and can't do its "auto-complete". Instead it loses focus and instead the width of the docking panel is getting changed.

I would like to avoid that behavior for both arrow keys and tab keys, so that the Microsoft WPF Terminal Control can do its thing.

Stenly
Telerik team
commented on 16 Apr 2025, 11:22 AM

Hello Dominic,

Thank you for taking the time to modify the sample project.

Instead of using the KeyUp event, you could use the PreviewKeyDown event and set its e.Handled property to True. This way, the button will update its content correctly, support the behavior with the left, right, and tab keys, and it will prevent the event from bubbling, meaning that focus will not go to another place in the RadDocking.

The following code snippet showcases what I have in mind:

public partial class TerminalView : UserControl
{
    public TerminalView()
    {
        InitializeComponent();
        this.Loaded += TerminalView_Loaded;
    }

    private void TerminalView_Loaded(object sender, System.Windows.RoutedEventArgs e)
    {
        ButtonToActAsDummyTerminal.PreviewKeyDown += ButtonToActAsDummyTerminal_PreviewKeyDown;
    }

    private void ButtonToActAsDummyTerminal_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
    {
        if (!(sender is Button button)) {
            return;
        }
        string currentButtonContent = string.Empty;
        if (button.Content is string buttonContentString) {
            currentButtonContent = buttonContentString;
        }
        switch (e.Key) {
            case System.Windows.Input.Key.Back:
            case System.Windows.Input.Key.Left:
                if (currentButtonContent.Length > 0) {
                    button.Content = currentButtonContent.Substring(0, currentButtonContent.Length - 1);
                }
                break;
            case System.Windows.Input.Key.Right:
            case System.Windows.Input.Key.Tab:
                button.Content = currentButtonContent + "AUTOCOMPLETE";
                break;
            default:
                button.Content = currentButtonContent + e.Key.ToString();
                break;
        }

        e.Handled = true;
    }
}

The produced result is as follows:

With this being said, could you give this suggestion a try and let me know how it goes?

1 Answer, 1 is accepted

Sort by
0
Accepted
Luigi
Top achievements
Rank 3
Bronze
Iron
Iron
answered on 24 Jan 2023, 10:23 AM

Yes,

I try and I achieved what I need.

Thank you

Luigi

Tags
Docking
Asked by
Luigi
Top achievements
Rank 3
Bronze
Iron
Iron
Answers by
Luigi
Top achievements
Rank 3
Bronze
Iron
Iron
Share this question
or