WPF 防止键盘调用

WPF Prevent keyboard invocation

我正在 Windows 10 上使用 .NET Framework 4.6.2 开发 WPF 应用程序。 使用此框架,当 TextBox 获得焦点时,键盘就会出现。 很好,但是如何仅在一个 TextBox 上禁用此键盘的自动调用? 事实上,如果我设置 ReadOnly="True" 那么键盘会继续出现。

您可以按照@Stalker 此处的建议覆盖TextBox class 的OnCreateAutomationPeer() 方法:

class MyTextBox : TextBox
{
    protected override AutomationPeer OnCreateAutomationPeer()
    {
        return new FrameworkElementAutomationPeer(this);
    }
}