Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a "type here" message to a WPF TextBox?

Tags:

c#

wpf

textbox

xaml

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?

like image 363
CannibalSmith Avatar asked Jan 28 '26 14:01

CannibalSmith


2 Answers

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.

like image 59
Gavin Miller Avatar answered Jan 31 '26 04:01

Gavin Miller


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

like image 43
Anvaka Avatar answered Jan 31 '26 04:01

Anvaka