[英]Disable autocompletion on windows tablet keyboard for textbox control in a Windows 8.1 store app?
[英]On Screen keyboard - Windows 8.1 Tablet
在過去的5年中,我們一直在致力於應用程序的開發,而現在我們要讓程序在Surface Pro 3上運行,我們遇到的主要問題是屏幕鍵盤單擊文本框時無法打開。
我正在嘗試找到一種方法來綁定一個應用程序范圍的事件,該事件將在每次觸摸文本框時打開鍵盤,這是否可能,還是我們需要遍歷整個應用程序並在我們認為我們會在任何時候手動觸發鍵盤需要它?
除非在WindowsStoreApplication中,否則單擊或觸摸文本框時似乎無法打開鍵盤。
我創建了一個鍵盤功能,大約2個月前在這里的其他地方找到了這個答案。 如果我可以再次找到它,我將使用鏈接對其進行更新。 我正在使用Surface 2 pro平板電腦,代碼為:
class KeyboardFunction
{
//Used for close keyboard method
[DllImport("user32.dll")]
public static extern int FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_CLOSE = 0xF060;
//End close keyboard inputs
/*
*Opens the tablet keyboard on device
*
*/
public void openKeyboardOnTablet()
{
System.Diagnostics.Process.Start(@"C:\Program Files\Common Files\Microsoft Shared\ink\TabTip.exe");
}
/*
*Close on screen keyboard
*
*/
public void closeOnscreenKeyboard()
{
// retrieve the handler of the window
int iHandle = FindWindow("IPTIP_Main_Window", "");
if (iHandle > 0)
{
// close the window using API
SendMessage(iHandle, WM_SYSCOMMAND, SC_CLOSE, 0);
}
}
}
據我所知,沒有辦法告訴表面只用數字打開鍵盤。 這只是打開默認鍵盤。 我試圖包括Surface dll,但是在我的C#桌面應用程序中什么也沒做。 希望這可以幫助!
這是在帶有WPF的Windows 8.1中執行此操作的一種方法,該代碼也可以在Windows 10中使用,除了您可能需要進行修改以更好地與新的Touch Panel and Handwriting Service
:
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Interactivity;
using System.Windows.Threading;
public class KeyboardFocusBehavior : Behavior<Control>
{
public bool Focused
{
get { return (bool)GetValue(FocusedProperty); }
set { SetValue(FocusedProperty, value); }
}
public static readonly DependencyProperty FocusedProperty = DependencyProperty.Register("Focused",
typeof(bool),
typeof(ControlKeyboardFocusBehavior),
new PropertyMetadata(false, OnFocusedPropertyChanged));
private static void OnFocusedPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
ControlKeyboardFocusBehavior b = d as ControlKeyboardFocusBehavior;
if(b != null && b.AssociatedObject != null)
{
Control c = b.AssociatedObject;
if (!c.IsFocused && (bool)e.NewValue)
{
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Input, new Action(delegate()
{
c.Focus();
Keyboard.Focus(c);
TouchKeyboard.Show();
}));
}
}
}
public class ShowTouchKeyboardOnFocusBehavior : Behavior<Control>
{
protected override void OnAttached()
{
base.OnAttached();
WeakEventManager<Control, KeyboardFocusChangedEventArgs>.AddHandler(AssociatedObject, "GotKeyboardFocus", OnGotKeyboardFocus);
WeakEventManager<Control, KeyboardFocusChangedEventArgs>.AddHandler(AssociatedObject, "LostKeyboardFocus", OnLostKeyboardFocus);
}
private void OnGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
// show the touch keyboard
TouchKeyboard.Show();
var textBox = sender as TextBox;
if (textBox != null)
textBox.SelectionStart = Math.Max(0, textBox.Text.Length);
}
private void OnLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
// hide the touch keyboard
TouchKeyboard.Hide();
}
}
然后在WPF XAML文件中,對於給定的文本框:
<Border CornerRadius="0,5,5,0" Style="{StaticResource TextBoxBorder}" >
<TextBox Style="{StaticResource TextBoxInput}" Text="{Binding MyTextProperty}" >
<i:Interaction.Behaviors>
<behaviors:ShowTouchKeyboardOnFocusBehavior />
</i:Interaction.Behaviors>
</TextBox>
</Border>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.