user2565280
user2565280

Reputation: 357

How to disable "." button in numeric input on screen keyboard Windows Phone 8

I want to use numeric input in Windows Phone 8. But I only want to used Numeric one with no char "." in it.

enter image description here

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

Answers (3)

user4004944
user4004944

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

uncle_scrooge
uncle_scrooge

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

sibbl
sibbl

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

Related Questions