Reputation: 1011
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!!!!
Upvotes: 16
Views: 23476
Reputation: 14409
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.
Upvotes: 48
Reputation: 520
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;
}
Upvotes: 7
Reputation: 3529
How to: Change the On-Screen Keyboard Input Scope in Windows Phone
<TextBox InputScope="Number" Name="txtPhoneNumber" />
Upvotes: 7