How can i set the keyboard to open in number mode or directly open a special numeric keyboard (as in android)??? My goal is to avoid the user to press the little button to toggle letters and numbers everytime before entering the value that may only be a numerical value. I have a textbox that the user needs to edit.Thanks!!!!
Asked
Active
Viewed 2.3k times
3 Answers
48
Set the InputScope
to Number
.
XAML
<TextBox InputScope="Number" Name="txtPhoneNumber" />
C#
InputScope scope = new InputScope();
InputScopeName name = new InputScopeName();
name.NameValue = InputScopeNameValue.Number;
scope.Names.Add(name);
txtPhoneNumber.InputScope = scope;
Above code snippets taken from this MSDN article which you can review for more information. As Martin added in the comment, you can also see screenshots of the different InputScope options here.

John
- 159
- 11

David Ruttka
- 14,269
- 2
- 44
- 39
-
2This link gives you screenshots of the InputScopes: http://msdn.microsoft.com/en-us/library/hh393998(v=vs.92).aspx – Martin Mar 13 '12 at 19:32
7
How to: Change the On-Screen Keyboard Input Scope in Windows Phone
<TextBox InputScope="Number" Name="txtPhoneNumber" />

Julien
- 3,509
- 20
- 35
7
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;
}

Cedric Michel
- 502
- 5
- 13
-
The best example I saw. No need to control all those special characters, just control those we need. Great. – Eagle Oct 02 '13 at 10:55