1

everyone i am facing a problem. i am on initial stage. please ignore if stupid question. i use "InputPrompt" control (from coding for fun toolkit) to getting the value in the form of phone number. when i try to enter the number in the form of i.e 123-345-6789 the cursor position changed and go back to the previous value. the code is :

// the event

input.TextInputStart += new TextCompositionEventHandler(input_TextInputStart);

// event handler

void input_TextInputStart(object sender, TextCompositionEventArgs e)
        {
            if(input.value.lenght == 2)
              {
                 input.value += '-';
              }
            if(input.value.lenght == 5)
              {
                 input.value += '-';
              }
             if(input.value.lenght == 9)
              {
                 input.value += '-';
              }

        }
4

3 回答 3

1

Input prompt don't allow the properties like textbox i.e selection, set cursor position etc. so we need to create the custom control in order to masking a phone number here is a link which tell about custom control. [Link] (http://developer.nokia.com/Community/Wiki/How_to_use_Pop-Ups_in_Windows_Phone)

于 2013-08-20T07:38:57.763 回答
0

You need this:

TextBox.SelectionStart(int start, int end);

if you do something like this:

void input_TextInputStart(object sender, TextCompositionEventArgs e)
    {
        if(input.value.lenght == 2)
          {
             input.value += '-';.
             input.SelectionStart(input.Length-1,input.Length-1);
          }
        if(input.value.lenght == 5)
          {
             input.value += '-';
             input.SelectionStart(input.Length-1,input.Length-1);
          }
         if(input.value.lenght == 9)
          {
             input.value += '-';
             input.SelectionStart(input.Length-1,input.Length-1);
          }

    }

Maybe syntax is incorrect, but method is what you need

于 2013-08-19T09:11:02.437 回答
0

Or you can derive from InputPrompt class and make public TextBox property, smth like:

public class MyInputPrompt : InputPrompt
{
    public TextBox MyInputBox
    {
        get { return this.InputBox; }
        set
        {
            if (value != this.InputBox)
            {
                this.InputBox = value;
            }
        }
    }
}
于 2013-11-26T08:55:14.227 回答