2013-08-19 100 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; 
      } 
     } 
    } 
}