我有以下代码。该窗口有一个文本框和一个复选框。如果我专注于复选框以外的任何内容并输入类似 123-456 的内容,那么对于每个字符PreviewKeyDown
并PreviewTextInput
正在触发。
但是,如果我将焦点放在复选框上,然后键入 123-456,那么PreviewKeyDown
会为所有字符PreviewTextInput
触发 ,而仅针对 123456 触发并且不会针对-. 连字符由复选框处理,而不是传递给PreviewTextInput
. 有没有办法得到连字符PreviewTextInput
?
public Window1()
{
InitializeComponent();
TextCompositionManager.AddTextInputHandler(this, new TextCompositionEventHandler(Window_PreviewTextInput));
}
private void Window_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
}
private void Window_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
}