WatermarkedTextBox Class

[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

A specialized TextBox that displays a customizable "watermark" whenever its contents are empty and it does not have the focus.

Namespace:  System.Windows.Controls
Assembly:  System.Windows.Controls.Extended (in System.Windows.Controls.Extended.dll)

[TemplatePartAttribute(Name = "Focused State", Type = typeof(Storyboard))]
[TemplatePartAttribute(Name = "Normal Watermarked State", Type = typeof(Storyboard))]
[TemplatePartAttribute(Name = "Disabled State", Type = typeof(Storyboard))]
[TemplatePartAttribute(Name = "Disabled Watermarked State", Type = typeof(Storyboard))]
[TemplatePartAttribute(Name = "RootElement", Type = typeof(FrameworkElement))]
[TemplatePartAttribute(Name = "MouseOver Watermarked State", Type = typeof(Storyboard))]
[TemplatePartAttribute(Name = "WatermarkElement", Type = typeof(ContentControl))]
[TemplatePartAttribute(Name = "Normal State", Type = typeof(Storyboard))]
[TemplatePartAttribute(Name = "MouseOver State", Type = typeof(Storyboard))]
public class WatermarkedTextBox : TextBox

The watermark is typically text that indicates the purpose of the TextBox. For example, a text box might display the text "Search" until the user enters a search term.

A watermark does not have to be a String. Any object that derives from UIElement can be used. For example, an empty WatermarkedTextBox might display an image or a TextBlock with customized properties.

The following XAML creates a page with two WatermarkedTextBox controls. The first WatermarkedTextBox control uses a simple text watermark and the second uses a control as a watermark.

<UserControl x:Class="WatermarkedTextBoxExample.Page"

    <Canvas x:Name="LayoutRoot" Background="White">
        <!-- Explanatory labels. -->
        <TextBlock Text="WatermarkedTextBox Demonstration" Margin="0,20,10,20"
            FontFamily="Verdana" FontSize="18" FontWeight="Bold"
            Foreground="#FF5C9AC9" Canvas.Left="20" Canvas.Top="0"/>

        <TextBlock Canvas.Top="60" Canvas.Left="20" Text="WatermarkedTextBox with a simple text watermark:" />
        <TextBlock Canvas.Top="140" Canvas.Left="20" Text="WatermarkedTextBox with a Button as a watermark:" />

        <!-- A TextBox with a simple text watermark. -->
        <WatermarkedTextBox Watermark="This is a watermark." 
                            Canvas.Top="90" Canvas.Left="20" 
                            Height="30" Width="200"/>

        <!-- A TextBox with a custom watermark. -->
        <!-- Any UIElement can serve as a watermark. -->
        <WatermarkedTextBox Canvas.Top="170" Canvas.Left="20" 
                            Height="75" Width="300">        
                <Button Height="60" Width="260" Content="This button serves as a watermark, too!" />

Run this sample.


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.