我正在开发windows 10操作系统的UWP应用程序。当用户单击文本框时,我需要显示触摸屏键盘。
以下是要求。
1.Windows 10操作系统
2.平板模式关闭
3.附硬件键盘。
我已经浏览了微软的示例https://github.com/microsoft/Windows-universal-samples/tree/master/Samples/TouchKeyboard。但却找不到解决办法。
我已经启用了“显示触摸键盘时,没有在平板模式和没有键盘附加”键盘设置。正如它所说的,它只在没有硬件键盘的情况下才能工作。
但我需要在有硬件键盘的情况下显示触摸屏键盘。
我尝试将InputPane作为以下代码示例使用:
MainPage.xaml
< TextBox x:Name="text1" Width="300" Height="50" ></TextBox>
MainPage.xaml.cs
{
this.InitializeComponent();
text1.AddHandler(TappedEvent, new TappedEventHandler(text1_Tapped), true);
}
private void text1_Tapped(object sender, TappedRoutedEventArgs e)
{
InputPane pane = InputPane.GetForCurrentView();
pane.TryShow();
}
这也没有显示触摸屏键盘时,硬件键盘是附加。
请指导我解决这一要求。
发布于 2019-12-22 19:09:16
发布于 2022-07-24 23:47:43
我能够使用CoreInputView.GetForCurrentView().TryShow(CoreInputViewKind.Keyboard).在桌面模式下显示/隐藏屏幕上的键盘
代码示例:
.xaml:
<TextBox GotFocus="TextBox_OnGotFocus" LostFocus="TextBox_OnLostFocus" InputScope="Number"/>
.xaml.cs:
private void TextBox_OnGotFocus(object _, RoutedEventArgs __)
{
CoreInputView.GetForCurrentView().TryShow(CoreInputViewKind.Keyboard);
}
private void TextBox_OnLostFocus(object _, RoutedEventArgs __)
{
CoreInputView.GetForCurrentView().TryHide();
}
此外,还可以通过设置InputScope值来控制键盘类型,例如: Number、NumericPin、Text或其他值:https://learn.microsoft.com/en-us/uwp/api/Windows.UI.Xaml.Input.InputScopeNameValue。
https://stackoverflow.com/questions/59433465
复制