Features
The RadWatermarkTextBox control supports watermark content, focus selection, and additional content. Its main properties are:
-
WatermarkContent—Gets or sets the watermark content. By default, it appears when the text box is empty and not focused. See WatermarkBehavior for other visibility modes. -
WatermarkTemplate—Gets or sets the template for the watermark content. Its visibility follows the same WatermarkBehavior setting asWatermarkContent. -
CurrentText—Gets or sets the text of the text box. Use this property withTwoWaybinding to update the binding source on each text change rather than when the control loses focus. -
IsWatermarkVisible—A read-only property that indicates whether the watermark is visible. -
SelectionOnFocus—Specifies how the selection changes when the control receives focus. TheSelectionOnFocusenumeration provides these values:-
Unchanged—Leaves the selection unchanged. -
SelectAll—Selects all text. -
CaretToBeginning—Moves the caret to the start of the text. -
CaretToEnd—Moves the caret to the end of the text.
-
-
AdditionalContent—Gets or sets an object rendered in aContentPresenteron the right side of the control. -
AdditionalContentTemplate—Gets or sets theSystem.Windows.DataTemplateused for theAdditionalContentobject.
The
RadWatermarkTextBoxcontrol is part of theTelerik.Windows.Controls.dllassembly.
For project setup and theme configuration, follow the RadWatermarkTextBox getting-started guide.
Using the WatermarkContent Property
Use the WatermarkContent property to define a prompt for an empty text box.
The following example displays a prompt asking for four digits, not a validation rule:
Setting the WatermarkContent property
<telerik:RadWatermarkTextBox x:Name="radWatermarkTextBox" WatermarkContent="Please Enter Four Digits:" />
RadWatermarkTextBoxwith watermark text

The WatermarkContent property is of type object, which means that you can set a value of any type. For example:
Defining custom content for the WatermarkContent property
<telerik:RadWatermarkTextBox x:Name="radWatermarkTextBox1">
<telerik:RadWatermarkTextBox.WatermarkContent>
<StackPanel Orientation="Horizontal">
<Image Source="/Silverlight.Help.RadMaskedTextBox;component/Images/EURFlag.png" />
<TextBlock Margin="3,0,0,0" Text="Please Enter Four Digits" />
</StackPanel>
</telerik:RadWatermarkTextBox.WatermarkContent>
</telerik:RadWatermarkTextBox>
RadWatermarkTextBoxwith custom watermark content

Using WatermarkTemplate Property
Use the WatermarkTemplate property to define a DataTemplate for the watermark content.
Defining the WatermarkTemplate
<telerik:RadWatermarkTextBox x:Name="radWatermarkTextBox2">
<telerik:RadWatermarkTextBox.WatermarkTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="/Silverlight.Help.RadMaskedTextBox;component/Images/EURFlag.png" />
<TextBlock Margin="3,0,0,0" Text="Please Enter Four Digits" />
</StackPanel>
</DataTemplate>
</telerik:RadWatermarkTextBox.WatermarkTemplate>
</telerik:RadWatermarkTextBox>
RadWatermarkTextBoxwith customWatermarkTemplate

Setting the SelectionOnFocus Property
The SelectionOnFocus property of RadWatermarkTextBox controls the text selection and caret position when the control receives focus. The following example sets SelectionOnFocus to SelectAll to select all text on focus.
Setting the SelectionOnFocus property
<telerik:RadWatermarkTextBox x:Name="radWatermarkTextBox3"
SelectionOnFocus="SelectAll"
WatermarkContent="Please Enter Four Digits:" />
WatermarkBehavior
The WatermarkBehavior property of RadWatermarkTextBox specifies when to hide the watermark content. It accepts these values:
HiddenWhenFocused—Hides the watermark when the control receives focus.HideOnClick—Hides the watermark when the user clicks the control.HideOnTextEntered—Hides the watermark when the user enters text into the control.
The default value is HiddenWhenFocused.
ReadOnlyBackground and DisabledBackground
The RadWatermarkTextBox control exposes DisabledBackground and ReadOnlyBackground to set its background in the disabled and read-only states, respectively.
Setting the DisabledBackground property
<telerik:RadWatermarkTextBox WatermarkContent="Please Enter Four Digits:" IsEnabled="False" DisabledBackground="DarkGray" />
Disabled
RadWatermarkTextBoxwith and withoutDisabledBackground

Setting the ReadOnlyBackground property
<telerik:RadWatermarkTextBox WatermarkContent="Please Enter Four Digits:" IsReadOnly="True" ReadOnlyBackground="DarkGray" />
Read-only
RadWatermarkTextBoxwith and withoutReadOnlyBackground

The read-only visual appears over the disabled visual.
ReadOnlyBackgroundtakes precedence overDisabledBackgroundwhen the control is both disabled and read-only.
Clear Command
The RadWatermarkTextBoxCommands class exposes the Clear command, which clears the text of the text box.
Using the Clear command
<StackPanel>
<telerik:RadWatermarkTextBox x:Name="watermarkTextBox" />
<telerik:RadButton Command="telerik:RadWatermarkTextBoxCommands.Clear"
CommandTarget="{Binding ElementName=watermarkTextBox}">
<telerik:RadGlyph Glyph="" />
</telerik:RadButton>
</StackPanel>
AdditionalContent and AdditionalContentTemplate
The RadWatermarkTextBox control exposes AdditionalContent and AdditionalContentTemplate to display and template additional content on its right side.
The following example demonstrates the AdditionalContent and AdditionalContentTemplate properties along with the Clear command.
Setting the AdditionalContent and AdditionalContentTemplate properties
<Grid>
<Grid.Resources>
<DataTemplate x:Key="ClearWatermarkTextBoxAdditionalContentTemplate">
<telerik:RadButton Focusable="False"
IsBackgroundVisible="False"
Command="telerik:RadWatermarkTextBoxCommands.Clear"
CommandTarget="{Binding ElementName=watermarkTextBox}">
<telerik:RadGlyph Glyph="{Binding}"/>
</telerik:RadButton>
</DataTemplate>
</Grid.Resources>
<telerik:RadWatermarkTextBox Name="watermarkTextBox"
AdditionalContent=""
AdditionalContentTemplate="{StaticResource ClearWatermarkTextBoxAdditionalContentTemplate}"/>
</Grid>
RadWatermarkTextBoxwith customAdditionalContentandAdditionalContentTemplateproperties
