For WPF, there isn't a way. You have to mimic it. See this example. A secondary (flaky solution) is to host a WinForms user control that inherits from TextBox and send the EM_SETCUEBANNER message to the edit control. ie.
Also, if you want to host a WinForm control approach, I have a framework that already includes this implementation called BitFlex Framework, which you can download for free here.
Here is an article about BitFlex if you want more information. You will start to find that if you are looking to have Windows Explorer style controls that this generally never comes out of the box, and because WPF does not work with handles generally you cannot write an easy wrapper around Win32 or an existing control like you can with WinForms.
You have to create a custom control by inheriting the textbox.
Below link has an excellent example about the search textbox sample.
Please have a look at this
To increase the re-usability of this Style, you can also create a set of attached properties to control the actual cue banner text, color, orientation etc.
Private Sub txtSearchBox_GotFocus(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles txtSearchBox.GotFocus
If txtSearchBox.Text = "Search" Then
txtSearchBox.Text = ""
Else
End If
End Sub
Private Sub txtSearchBox_LostFocus(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles txtSearchBox.LostFocus
If txtSearchBox.Text = "" Then
txtSearchBox.Text = "Search"
Else
End If
End Sub
It works well, but the text is in gray still. Needs cleaning up. I was using VB.NET
@sellmeadog :Application running, bt Design not loading...the following Error comes:
Ambiguous type reference. A type named 'StaticExtension' occurs in at least two namespaces, 'MS.Internal.Metadata.ExposedTypes.Xaml' and 'System.Windows.Markup'. Consider adjusting the assembly XmlnsDefinition attributes.
'm using .net 3.5
this works also with PasswordBox. If you want to use it with TextBox, simply exchange PasswordChangedwith TextChanged.
XAML:
<Grid>
<!-- overlay with hint text -->
<TextBlock Margin="5,2"
Text="Password"
Foreground="Gray"
Name="txtHintPassword"/>
<!-- enter user here -->
<PasswordBox Name="txtPassword"
Background="Transparent"
PasswordChanged="txtPassword_PasswordChanged"/>
</Grid>
You can do in a very simple way.
The idea is to place a Label in the same place as your textbox. Your Label will be visible if textbox has no text and hasn't the focus.
Bonus:If you want to have default value for your textBox, be sure after to set it when submitting data (for example:"InputText"="PlaceHolder Text Here" if empty).
I once got into the same situation, I solved it following way.
I've only fulfilled the requirements of a hint box, you can make it more interactive by adding effects and other things on other events like on focus etc.
WPF CODE (I've removed styling to make it readable)