In a WPF TextBox I'd like to provide a description that vanishes after the first input. This should provide a little help to the user what he should enter in the text field.
The text could be displayed above the given TextBox using a Label. I am interested in an example, but couldn't find any. Ideally the solution is XAML only.
.Net 4 Version of Christians solution, it also doesn't need the aero library:
I have put together a complete example based on the provided link from anvarbek raupov (http://blogs.windowsclient.net/swt62/archive/2009/05/10/wpf-textbox-watermark-the-easy-way.aspx). The trick is to add an additional label above the text box, that is only displayed when then content of the text box is empty and not focused. The condition is implemented in XAML using Triggers. My example style lets the text box style unchanged from the normal behavior.
The example consists of a commented resource dictionary (WatermarkResource.xaml) and a MainWindow.xaml with a normal and a watermarked text box. The code behind does only the initialization and is unchanged from a wizard generated WPF application.
This is the WatermarkResource.xaml:
And this is the MainWindow.xaml:
This is a screenshot of the running application with the visible Watermark
and this is with some text, where the Watermark is hidden
For anyone who might be interested in this question, check material design (http://materialdesigninxaml.net/).
With this library, it is really easy :
Here's a XAML only solution, using rather basic "mechanisms".
I'm in no way an expert on XAML. There are probably better and/or more elegant ways to do that, but this is what I got by trying and combining stuff I found on this site.
I thought it is quite straight forward, explicit and this can be useful to some ...
Feel free to comment on any issues or things that can be done better.