我有一个文本框的用户控件。在用户控件的代码隐藏中,我有一个名为" TextBoxText_PreviewMouseDown"的函数,它显示了一个屏幕键盘:
private void TextBoxText_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
TextBox textbox = sender as TextBox;
US_Keyboard keyboardWindow = new US_Keyboard(textbox, Window.GetWindow(this));
if (keyboardWindow.ShowDialog() == true)
textbox.Text = keyboardWindow.InputSource.Text;
}
我的问题是,如果显示onscreenkeyboard,它会获得焦点,为此,光标在文本框中消失。
onscreenkeyboard是自制的wpf键盘(US_Keyboard),带有用于键盘ui的xaml文件和用于键盘逻辑的代码隐藏文件。
这是键盘的构造函数:
public US_Keyboard(TextBox owner, Window wndOwner)
{
InitializeComponent();
MainWindow = wndOwner;
this.Owner = wndOwner;
this.DataContext = this;
InputSource = owner;
SetKeyboardSize();
SetKeyboardPosition();
}