Reputation: 357
I want to use numeric input in Windows Phone 8. But I only want to used Numeric one with no char "." in it.
This is the picture of numeric input that I used in windows phone 8, what im gonna to do is disable the "." in the bottom left of the picture. How i can do that ? Thanks before
Upvotes: 0
Views: 2582
Reputation:
You can just write the following code on key down event of the TextBox control
private void YourTextBox_OnKeyDown(object sender, KeyEventArgs e)
{
if (e.PlatformKeyCode == 190)
{
e.Handled = true;
}
}
Upvotes: 1
Reputation: 429
Hi you can use like this---
<TextBox .... InputScope="Digits" ....> in xaml
This will still add the '.' key in the keyboard. To prevent users from typing it you add the KeyUp event to the TextBox and do the following: in code behind--
private void KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
{
TextBox txt = (TextBox)sender;
if (txt.Text.Contains('.'))
{
txt.Text = txt.Text.Replace(".", "");
txt.SelectionStart = txt.Text.Length;
}
}
Upvotes: 1
Reputation: 3229
Use the following code, which does ignore the press of the "." key:
XAML:
<TextBox InputScope="Number" KeyDown="TextBox_OnKeyDown" />
C#:
private void TextBox_OnKeyDown(object sender, KeyEventArgs e)
{
e.Handled = !System.Text.RegularExpressions.Regex.IsMatch(e.Key.ToString(), "[0-9]");
}
Upvotes: 0