Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to place "hints" in Windows Phone 7 TextBoxes?

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.

like image 465
Rob S. Avatar asked May 26 '11 00:05

Rob S.


2 Answers

What you're looking for is normally called a "Watermarked" textbox. It's quite simple to create a control which implements this functionality.

Here are links to a few versions of implementations of this:

  • http://blogs.msdn.com/b/arun/archive/2010/03/29/watermarked-text-box-for-windows-phone.aspx
  • http://www.windowsphonegeek.com/articles/WP7-WatermarkedTextBox-custom-control
  • http://www.danielmoth.com/Blog/Watermark-TextBox-For-Windows-Phone.aspx
  • http://weblogs.asp.net/jdanforth/archive/2010/09/17/silverlight-watermark-textbox-behavior.aspx
  • WatermarkedTextBox for Windows Phone 7?
  • http://www.silverlight-zone.com/2011/03/wp7-watermarkedtextbox-custom-control.html
  • http://watermarktextbox.codeplex.com/
like image 154
Matt Lacey Avatar answered Oct 20 '22 00:10

Matt Lacey


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?

like image 42
Lukasz Madon Avatar answered Oct 20 '22 00:10

Lukasz Madon