如何将键盘设置为数字模式或直接打开特殊的数字键盘(如Android)?我的目标是避免用户在输入可能仅为数字值的值之前每次按小按钮切换字母和数字。我有一个需要用户编辑的文本框。谢谢!
如何将键盘设置为数字模式或直接打开特殊的数字键盘(如Android)?我的目标是避免用户在输入可能仅为数字值的值之前每次按小按钮切换字母和数字。我有一个需要用户编辑的文本框。谢谢!
将InputScope
设置为Number
。
XAML
<TextBox InputScope="Number" Name="txtPhoneNumber" />
C#
=>C#
InputScope scope = new InputScope();
InputScopeName name = new InputScopeName();
name.NameValue = InputScopeNameValue.Number;
scope.Names.Add(name);
txtPhoneNumber.InputScope = scope;
以上代码片段摘自这篇MSDN文章,你可以查看更多信息。正如Martin在评论中添加的那样,你还可以在这里查看不同输入范围选项的屏幕截图。
InputScope="Number"
TextBox numercicTextBox = new TextBox();
// ...propriétés de la textbox à initialiser + l'ajouter dans le ContentPanel
numercicTextBox.KeyDown += new KeyEventHandler(numercicTextBox_KeyDown);
void numercicTextBox_KeyDown(object sender, KeyEventArgs e)
{
if (System.Text.RegularExpressions.Regex.IsMatch(e.Key.ToString(),"[0-9]"))
e.Handled = false;
else e.Handled = true;
}
<TextBox InputScope="Number" Name="txtPhoneNumber" />