6

I just got started programming for Windows Phone 7 after programming on Android for about half a year now. In Android, when I wanted textual input from a user, I would put a "hint" in the text box which would tell the user what they should input. When the text box was selected the hint would disappear. So far I've only seen ways to set text inside text boxes. The problem with this is that the text does not disappear when the user selects the text box forcing the user to erase the currently existing text.

I did some Google searches and skimmed through relevant documentation as well as a book I have but I've not found an answer yet. Thank you very much in advance for your time answering my question.

Rob S.
  • 3,599
  • 6
  • 30
  • 39
  • 2
    It's possible in standard Silverlight, so maybe you can do it in WP7 too? http://www.solutionbot.com/2010/06/02/silverlight-watermark-textbox/ – Matt Greer May 26 '11 at 00:11
  • possible duplicate of [WatermarkedTextBox for Windows Phone 7?](http://stackoverflow.com/questions/5141325/watermarkedtextbox-for-windows-phone-7) – ctacke Sep 25 '11 at 15:48

2 Answers2

2

As I understand you want something similar to the default text in the searchbox (upper right corner of stackoverflow.com).

You have a few options.

Bool to check if user press the TextBox for the first time.

private bool m_textBoxPressedFirstTime = false;

and inside the event (double click the TextBox)

if(!m_textBoxPressedFirstTime)
{
    myTextBox.Text = String.Empty;
    m_textBoxPressedFirstTime = true; 
}

Define your own template with a diffrent visual state.
You could use some WPF examples How do you implement default text for a search box in WPF?

Community
  • 1
  • 1
Lukasz Madon
  • 14,664
  • 14
  • 64
  • 108