1.通过nuget安装 osklib.wpf
2.在textbox getFoucs中敲入如下代码即可实现获得焦点弹出软键盘
private void txtPLC_IP_GotFocus(object sender, RoutedEventArgs e)
{
try
{
// Osklib.OnScreenKeyboard.Close();
Osklib.OnScreenKeyboard.Show();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
3.如果界面上的textbox比较,就直接在窗体事件中写。注意第一句为判断是否为textbox
private void Grid_GotFocus(object sender, RoutedEventArgs e)
{
if (!(e.OriginalSource is TextBox))
return;
try
{
Osklib.OnScreenKeyboard.Show();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}