我在使用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. 如何隱藏軟鍵盤?
- 8. Windows 8 metro應用程序鍵盤位置改變
- 9. 當隱藏軟鍵盤時隱藏光標來自editText
- 10. 隱藏軟鍵盤
- 11. 帶有inputType和textAlignment的EditText使軟鍵盤隱藏EditText
- 12. Android - 鍵盤隱藏editText
- 13. 如何使用androidviewclient隱藏軟鍵盤
- 14. 隱藏iOS軟鍵盤AngularJS
- 15. 隱藏更衣室應用軟鍵盤
- 16. 隱藏應用程序簡歷上的軟鍵盤
- 17. 可靠隱藏軟鍵盤
- 18. 如何在android中隱藏軟鍵盤
- 19. 從其他應用程序恢復後隱藏軟件鍵盤
- 20. 在應用程序加載時隱藏軟鍵盤
- 21. 隱藏軟鍵盤問題
- 22. 在Win 8 DirectX Metro應用程序中使用內置軟鍵盤
- 23. 如何在WindowsPhone/Windows 8.1上按Enter鍵時隱藏軟鍵盤?
- 24. 如何有效隱藏Windows Phone 8.1軟鍵盤?
- 25. 如何隱藏iPad中的軟鍵盤
- 26. 如何在WebView中隱藏軟鍵盤?
- 27. Android軟鍵盤隱藏RecyclerView
- 28. Android:AutoCompleteTextView隱藏軟鍵盤
- 29. 避免隱藏軟鍵盤
- 30. 如何隱藏WP7中的軟鍵盤?
這是不可能的Win8 CP。可能的重複:http://stackoverflow.com/questions/10129550/show-hide-keyboard-programmatically-on-windows8 –
如果在這個問題上的任何其他選擇。 – Narasimha