WatermarkedTextBox Class Home
.NET Framework Class Library for Silverlight
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)

Syntax

'Usage

Dim instance As WatermarkedTextBox

'Declaration

<TemplatePartAttribute(Name := "Focused State", Type := GetType(Storyboard))> _
<TemplatePartAttribute(Name := "Normal Watermarked State", Type := GetType(Storyboard))> _
<TemplatePartAttribute(Name := "Disabled State", Type := GetType(Storyboard))> _
<TemplatePartAttribute(Name := "Disabled Watermarked State", Type := GetType(Storyboard))> _
<TemplatePartAttribute(Name := "RootElement", Type := GetType(FrameworkElement))> _
<TemplatePartAttribute(Name := "MouseOver Watermarked State", Type := GetType(Storyboard))> _
<TemplatePartAttribute(Name := "WatermarkElement", Type := GetType(ContentControl))> _
<TemplatePartAttribute(Name := "Normal State", Type := GetType(Storyboard))> _
<TemplatePartAttribute(Name := "MouseOver State", Type := GetType(Storyboard))> _
Public Class WatermarkedTextBox _
    Inherits TextBox
Remarks

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.

Examples

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"
        xmlns="http://schemas.microsoft.com/client/2007" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        Width="400"
        Height="300"
        >

    <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">        
            <WatermarkedTextBox.Watermark>
                <Button Height="60" Width="260" Content="This button serves as a watermark, too!" />
            </WatermarkedTextBox.Watermark>
        </WatermarkedTextBox>
    </Canvas>
</UserControl>

Run this sample.

Inheritance Hierarchy

System..::.Object
  System.Windows.Controls..::.Control
    System.Windows.Controls..::.TextBox
      System.Windows..::.DependencyObject
        System.Windows..::.FrameworkElement
          System.Windows..::.UIElement
            System.Windows.Controls..::.WatermarkedTextBox
Thread Safety

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

Reference

Other Resources

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View