C# WPF模拟按键关闭事件未按预期工作

C# WPF模拟按键关闭事件未按预期工作,c#,wpf,keyboard,virtual,C#,Wpf,Keyboard,Virtual,我正在为数字的触摸输入创建一个虚拟数字键盘。我使用以下函数提升文本框的PreviewKeyDown和KeyDown事件: private void PerformKeyInput(Key key) { var target = this.dialogWindow.TextInputField; // Target element var previewKeyDownEvent = Keyboard.PreviewKeyDownEvent;

我正在为数字的触摸输入创建一个虚拟数字键盘。我使用以下函数提升文本框的PreviewKeyDown和KeyDown事件:

    private void PerformKeyInput(Key key)
    {
        var target = this.dialogWindow.TextInputField; // Target element

        var previewKeyDownEvent = Keyboard.PreviewKeyDownEvent;
        target.RaiseEvent(
            new KeyEventArgs(Keyboard.PrimaryDevice, PresentationSource.FromVisual(target), 0, key)
            {
                RoutedEvent = previewKeyDownEvent
            });

        var keyDownEvent = Keyboard.KeyDownEvent;
        target.RaiseEvent(
            new KeyEventArgs(Keyboard.PrimaryDevice, PresentationSource.FromVisual(target), 0, key)
            {
                RoutedEvent = keyDownEvent
            });
    }
我还将文本属性绑定的UpdateSourceTrigger更改为PropertyChanged

<TextBox Text="{Binding TextBoxInput, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">


我现在的问题是,这个函数只适用于Key.Back、Key.Left和Key.right,但不适用于Key.Num0或Key.D1等数字。为什么将数字键笔划发送到文本框不起作用?

您尝试过使用功能吗?谢谢,这似乎是我在这里需要的。您尝试过使用功能吗?谢谢,这似乎是我在这里需要的。