2013-08-19 85 views
1

每个人我都面临一个问题。我正处于初始阶段。如果愚蠢的问题请忽略。 我使用“InputPrompt”控件(从有趣的工具包编码)获取电话号码形式的值。当我尝试以123-345-6789的形式输入数字时,光标位置发生变化并返回到先前的值。代码:PhoneNumber屏蔽输入提示

//事件

input.TextInputStart += new TextCompositionEventHandler(input_TextInputStart); 

//事件处理

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 += '-'; 
       } 

     } 

回答

0

你需要这样的:

TextBox.SelectionStart(INT开始,诠释完);

,如果你做这样的事情:

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); 
      } 

    } 

也许语法不正确的,但方法是你所需要的

+0

并且在输入端没有selectionstart方法提示 – HmXa

+0

这是无法使用手机输入提示中的数字掩码。我们只需要创建一个自定义控件。这里是一个helle [链接](http://developer.nokia.com/Community/Wiki/How_to_use_Pop-Ups_in_Windows_Phone) – HmXa

0

或者你也可以从InputPrompt类派生和公开文本框属性,水木清华这样的:

public class MyInputPrompt : InputPrompt 
{ 
    public TextBox MyInputBox 
    { 
     get { return this.InputBox; } 
     set 
     { 
      if (value != this.InputBox) 
      { 
       this.InputBox = value; 
      } 
     } 
    } 
}