tags:

views:

145

answers:

3

If the text box has no keyboard focus and no text, then show italic gray "type here" text "inside" it. How? What doesn't work:

  • Setting the Text property - it messes up data binding.
  • Overriding the template - it's messy and overridden already anyway.

Preferably, I'd like the solution to be as much XAML and as little C# as possible. Perhaps I could create an attached property that would do some magic?

+3  A: 

What you're looking for is known as a Watermark. I'm unfamiliar with WPF, but searching WPF & Watermark on "the google" returns a ton of results.

Gavin Miller
+1 for your answer :). Watermarked text is very popular in WPF/Silverlight/whatnot and there are hundreds solutions out there...
Anvaka
A: 

Not the cleanest solution, but you could always add a TextBlock overlaying the TextBox and change it's Visible property when the TextBox gains or loses focus.

Nasty hack, but somewhat innovative? Do I get brownie points for that? ;-)

Daniel May
A: 

The best solution I've seen till now, is InfoTextBox from Kevin's WPF Bag-o-Tricks library. Check it out.

Anvaka