locked
Formatting Text Boxes RRS feed

  • Question

  • Hey,

    I'm wondering if there is a way to format a textbox to take input in a certain format.

    For example, in Microsoft Access you can format a cell to accept telephone numbers, so when you select the cell it looks like "(___) ___-____". Is it possible to format a textbox in XAML to imitate this feature?

     

    I have looked into a feature called StringFormat but it seems as if that only works when the cell is bound to data.

     

    Any help would be great!

     

     

    Thanks

    Friday, October 29, 2010 3:13 PM

Answers

  • You could also do this just by handling the click, and typing events to do what you want.

     

    When you first type a character, clear the contents, then when you hit what you want, remove focus.

     

    • Marked as answer by jh08tt Friday, October 29, 2010 4:38 PM
    Friday, October 29, 2010 4:26 PM
    Moderator

All replies

  • What you are looking for is validation. Here is a posting about how to do it in SL:

    http://silverlighttips.com/post/2009/10/08/SilverlightValidationTextBox.aspx

    Hopefully that will get you started, let me know if you need more info and we'll be happy to help.

    Friday, October 29, 2010 3:53 PM
    Moderator
  • What I’m looking for isn't so much validation, but something similar to pre-populated data that represents how the data should be entered (but is overwritten as you type).

    Currently I just have ##.### in the text box to demonstrate this, but the users do not like this (sometimes I think they forget it's a prototype).

    Ideally, my end goal is to have the text box formatted a certain way and receive a maximum of 5 characters then auto tab out of the field.

     

    Your answer was good though, it actually helped answer another question I had!!!

     

    Thanks

    Friday, October 29, 2010 4:09 PM
  • You could also do this just by handling the click, and typing events to do what you want.

     

    When you first type a character, clear the contents, then when you hit what you want, remove focus.

     

    • Marked as answer by jh08tt Friday, October 29, 2010 4:38 PM
    Friday, October 29, 2010 4:26 PM
    Moderator