我在使用C#的框架中有一个EditText和一个按钮。在编辑区内写入并单击按钮后,我想要隐藏虚拟软键盘。如何隐藏EditText软键盘windows 8 Metro应用程序?
回答
你不能。有关于Input Hosting Manager and Soft Keyboard的行为的更多信息,您可以register to know when it shows or becomes hidden。但是,您无法以编程方式控制它是启动还是关闭。
我不明白为什么这是被接受的答案。按照罗伯特的建议,将焦点放在隐藏的按钮上,完美地工作。一个人必须抓住一些角落的情况,但最终的用户体验要好得多...... –
尝试设置Textbox`的IsReadOnly
财产。
我做得“差不多”
private void textbox_input_LostFocus(object sender, RoutedEventArgs e)
{
textbox_input.IsReadOnly = false;
}
private void textbox_input_Tapped(object sender, TappedRoutedEventArgs e)
{
if(e.PointerDeviceType != Windows.Devices.Input.PointerDeviceType.Mouse)
textbox_input.IsReadOnly = true;
else
textbox_input.IsReadOnly = false;
}
有了这个剪断我,如果用户不使用鼠标抑制键盘...
另外,KeyDown
事件而解雇文本框是只读的,因此你可以直接利用这些数据来设置您的视图模型,并更新了它的文本框;)
添加一个虚拟按钮,将焦点设置到它和键盘将被隐藏。
我这样做,但设置了“IsTabStop =”true“'并将'Height' /'Width'设置为'”0“',而不是'可见性=“折叠”'。这是我对环境的神奇结合。 –
感谢您的问题。 我已经为这个问题得到了更好的解决方案。这样
首先我们可以在XAML
<Grid x:Name= Tapped="Grid_Tapped_1">
......
</Grid >
添加处理程序,然后我们注重当前页面类似如下。它运作良好。
private void Grid_Tapped_1(object sender, TappedRoutedEventArgs e)
{
this.Focus(FocusState.Programmatic);
}
当显示虚拟键盘的文本框将它的IsEnabled设置为false时,虚拟键盘消失。我们可以立即设置为true,虚拟键盘将保持隐藏状态。就像这样:
MyTextBox.KeyDown += (s, a) => {
if (a.Key == VirtualKey.Enter) {
MyTextBox.IsEnabled = false;
MyTextBox.IsEnabled = true;
}
};
There是可以通过设置隐藏触摸键盘溶液的容器的IsTabStop=true
点击您的按钮为“提交”后,全自动。
但是,顺便说一句,我已经注意到,下一次进入该页面时,EditText
(应该是TextBox
)将自动对焦,并有触摸键盘显示。也许你最好在提交后禁用EditText
。 (似乎完成并阻止输入操作)
我有同样的问题,只是有一点差别。 当我从文本框切换到日期选择器时,软键盘不会消失。
我尝试了所有的你的建议,但是毫无效果像它应该。每次我的datepicker有一个奇怪的行为后,我尝试了上述解决方案之一(或其他一些其他stackoverflow线程)。
一段时间后,我发现通过谷歌的东西,它的工作就像一个魅力。 HERE
在评论部分Dusher16写了一个非常干净的解决方案,它也适用于WinRT/Win8/Win8.1/Metro或者你将如何调用它。
创建一个新类:
using System.Runtime.InteropServices;
using Windows.Devices.Input;
namespace Your.Namespace
{
public static class TouchKeyboardHelper
{
#region <Attributes>
private const int WmSyscommand = 0x0112; // Flag to received/send messages to the system.
private const int ScClose = 0xF060; // Param to indicate we want to close a system window.
#endregion <Attributes>
#region <Properties>
public static bool KeyboardAttached
{
get { return IsKeyboardAttached(); }
}
#endregion <Properties>
#region <Methods>
[DllImport("user32.dll")]
private static extern int FindWindow(string lpClassName, string lpWindowName); // To obtain an active system window handler.
[DllImport("user32.dll")]
private static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam); // To send a message to the system.
/// <summary>
/// To detect if a real keyboard is attached to the dispositive.
/// </summary>
/// <returns></returns>
private static bool IsKeyboardAttached()
{
KeyboardCapabilities keyboardCapabilities = new KeyboardCapabilities(); // To obtain the properties for the real keyboard attached.
return keyboardCapabilities.KeyboardPresent != 0 ? true : false;
}
/// <summary>
/// To close the soft keyboard
/// </summary>
public static void CloseOnscreenKeyboard()
{
// Retrieve the handler of the window
int iHandle = FindWindow("IPTIP_Main_Window", ""); // To find the soft keyboard window.
if (iHandle > 0)
{
SendMessage(iHandle, WmSyscommand, ScClose, 0); // Send a close message to the soft keyboard window.
}
}
#endregion <Methods>
}
}
而在例如一些XAML.cs文件添加以下行:
private void DatePicker_GotFocus(object sender, RoutedEventArgs e)
{
if (TouchKeyboardHelper.KeyboardAttached)
TouchKeyboardHelper.CloseOnscreenKeyboard();
}
- 1. 未隐藏Windows 8软键盘
- 2. 软键盘隐藏的EditText
- 3. 如何隐藏EditText上的软键盘
- 4. 如何在软键盘显示时隐藏EditText软键盘?
- 5. 如何隐藏软键盘?
- 6. Android:触摸EditText时隐藏软键盘
- 7. 当隐藏软键盘时隐藏光标来自editText
- 8. Windows 8 metro应用程序键盘位置改变
- 9. 隐藏软键盘
- 10. 带有inputType和textAlignment的EditText使软键盘隐藏EditText
- 11. 隐藏应用程序简历上的软键盘
- 12. 如何在android中隐藏软键盘
- 13. 从其他应用程序恢复后隐藏软件键盘
- 14. 在应用程序加载时隐藏软键盘
- 15. 隐藏软键盘问题
- 16. 在Win 8 DirectX Metro应用程序中使用内置软键盘
- 17. 如何在WindowsPhone/Windows 8.1上按Enter键时隐藏软键盘?
- 18. 如何有效隐藏Windows Phone 8.1软键盘?
- 19. 如何隐藏iPad中的软键盘
- 20. 如何在WebView中隐藏软键盘?
- 21. 如何隐藏WP7中的软键盘?
- 22. Android软键盘如何不响应EditText?
- 23. 隐藏android软键盘当软键盘按一键时
- 24. HtmlAgilityPack和Windows 8 Metro应用程序
- 25. SQlite与Windows 8 Metro应用程序
- 26. Windows 8 Metro应用程序Iframe
- 27. Windows 8 Metro应用程序 - 渲染PNGs
- 28. 隐藏安卓软键盘,只允许EditText上的数字
- 29. 在新页面上隐藏软键盘
- 30. 软键盘隐藏多行EditText下面的按钮?
这是不可能的Win8 CP。可能的重复:http://stackoverflow.com/questions/10129550/show-hide-keyboard-programmatically-on-windows8 –
如果在这个问题上的任何其他选择。 – Narasimha