Arun
Arun

Reputation: 3456

How to show only digit keys in keyboard windows phone 7?

I am developing a windows phone app and am new in wp7 development. I am using a text box to enter amount of a product. Only digits are allowed to enter in to that field. So my need is to display digits (0 to 9) in the keypad. How can I do this ?.. Please help.

I tried the following code

<TextBox Name="textBox1" Width="200" Height="100" Text="0.00" TextAlignment="Right">
            <TextBox.InputScope>
                <InputScope>
                    <InputScopeName NameValue="CurrencyAmount"  />
                </InputScope>
            </TextBox.InputScope>
        </TextBox>

But still it showing the keyboard below.

enter image description here

Upvotes: 2

Views: 1174

Answers (2)

MengMeng
MengMeng

Reputation: 1024

        <TextBox.InputScope>
            <InputScope>
                <InputScopeName NameValue="Number"  />
            </InputScope>
        </TextBox.InputScope>

you just need 0~9

so += the keydown event of textblock

and use these code

        switch (e.Key)
        {
            case Key.D0:
            case Key.D1:
            case Key.D2:
            case Key.D3:
            case Key.D4:
            case Key.D5:
            case Key.D6:
            case Key.D7:
            case Key.D8:
            case Key.D9:
            case Key.Back:
            case Key.Delete:
                break;
            default:
                e.Handled = true;
                return;
        }

Upvotes: 1

Adrian F&#226;ciu
Adrian F&#226;ciu

Reputation: 12562

You can use InputScope property on the TextBox.

For example: <TextBox InputScope="Number"/>

or : <TextBox InputScope="CurrencyAmount"/>

For more information you can look here. You can find all the possible values for InputScope here.

You can see here visually how all the input scopes look like.

Also be sure that you'll validate the input in the code behind, for example user might have a physical keyboard on the device.

Upvotes: 3

Related Questions