Tablet PC输入面板不会导致TextInput事件?

Dan*_*iel 6 c# wpf textinput

我有一个消耗WPF TextInput事件的自定义控件.这在使用键盘时工作正常; 但是,如果使用"Tablet PC输入面板"(Windows 7附带)的手写识别,单击"插入"按钮时不会发生TextInput事件.

public partial class Window1 : Window
{
    public Window1()
    {
    }

    protected override void OnTextInput(TextCompositionEventArgs e)
    {
        base.OnTextInput(e);
        this.Title = e.Text;
    }
}

class Text : Control
{
    static Text()
    {
        KeyboardNavigation.IsTabStopProperty.OverrideMetadata(
            typeof(Text), new FrameworkPropertyMetadata(true));
        KeyboardNavigation.TabNavigationProperty.OverrideMetadata(
            typeof(Text), new FrameworkPropertyMetadata(KeyboardNavigationMode.None));
        FocusableProperty.OverrideMetadata(
            typeof(Text), new FrameworkPropertyMetadata(true));
    }

    public static readonly DependencyProperty EnteredTextProperty =
        DependencyProperty.Register("EnteredText", typeof(string), typeof(Text),
                                    new FrameworkPropertyMetadata());

    public string EnteredText {
        get { return (string)GetValue(EnteredTextProperty); }
        set { SetValue(EnteredTextProperty, value); }
    }

    protected override void OnTextInput(TextCompositionEventArgs e)
    {
        this.EnteredText = e.Text;
        e.Handled = true;
    }

    /// <inheritdoc/>
    protected override void OnMouseDown(MouseButtonEventArgs e)
    {
        base.OnMouseDown(e);
        Focus();
    }
}
Run Code Online (Sandbox Code Playgroud)

这是XAML:

<Window x:Class="TestProject.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Height="300" Width="300"
>
    <local:Text xmlns:local="clr-namespace:TestProject">
        <Control.Template>
            <ControlTemplate TargetType="local:Text">
                <Border Background="Beige">
                    <Viewbox>
                        <TextBlock Text="{TemplateBinding EnteredText}"/>
                    </Viewbox>
                </Border>
            </ControlTemplate>
        </Control.Template>
    </local:Text>
</Window>
Run Code Online (Sandbox Code Playgroud)

应用程序启动时,文本输入将显示在标题栏中.这适用于键盘和手写识别.在窗口中单击以使控件聚焦后,只有键盘可用于输入; 手写识别被忽略了.

有谁知道出了什么问题?为什么我在一个案例中获得TextInput事件而在另一个案例中没有?这是WPF中的错误吗?有工作吗?

zee*_*zee 1

插入后,控件将失去其焦点属性,并且如果您在 MouseDown 事件上调用 Focus(),则不会恢复它们(因为实际上它已获得焦点,并且 OnFocus 事件不会再次释放)。

如果您聚焦其他控件并将自定义控件再次聚焦,则会发生 TextInput 事件(直到您再次从平板电脑输入插入文本)。

我无法解释发生了什么,我认为这可能是 WPF 的错误,但也许该信息可以帮助解决问题......