WPF Textbox focus without showing onscreen keyboard

136 views Asked by At

I have a WPF application that will generally be operated on a touch screen.

Numeric entry is via our own dialog that pops up when certain fields are clicked.

I don't want the default Windows 10/11 onscreen keyboard to appear when doing so. I can almost get the results I want by setting IsReadOnly and IsReadOnlyCaretVisible to true.

However the onscreen keyboard still displays for half a second or so when the dialog opens or the user clicks on the field, this doesn't occur if I set focusable to false on my text field however the user then can't see or manipulate the carat in the text box.

Does anybody know why the onscreen keyboard still pops up when IsReadOnly is set to True?

1

There are 1 answers

0
Hugoagogo On

For what its worth I did find a solution, even if I am not a huge fan of it as it involves replacing all instances of textbox with a subclass.

/// <summary>
/// This is wapper around text box for a that prevents the unneeded virtual keyboard poping up
/// </summary>
public class TextBoxNoKeyboard : TextBox
{
    protected override AutomationPeer OnCreateAutomationPeer()
    {
        return new FrameworkElementAutomationPeer(this);
    }
}

I dont really know why it works or what FrameworkElementAutomationPeer does

The solution was found here on the Microsoft forums