RadWatermarkTextBox control represents a TextBox that shows a
different content when empty and not focus. The most important properties of the RadWatermarkTextBox control are:
- WatermarkContent - gets or sets the content to be shown when the TextBox is empty and not focused.
- WatermarkTemplate - gets or sets the template for presenting the content, shown when the TextBox is empty and not focused.
- CurrentText - gets or sets the text of the TextBox. This property is meant to be used for TwoWay binding in order to be updated on each change of the text and not when the focus is lost.
- IsWatermarkVisible - a read-only property indicating whether the Watermark is visible or not.
- SelectionOnFocus - specifies the modification over the selection when the control receives focus. The values for this properties are predefined in the SelectionOnFocus enumeration, which exposes the following fields:
- Unchanged - selection will not be modified.
- SelectAll - the whole text will be selected.
- CaretToBeginning - the caret will be moved at the start of the text.
- CaretToEnd - the caret will be moved at the end of the text.
Tip |
|---|
| The RadWatermarkTextBox control is part of the Telerik.Windows.Controls.dll assembly. |
Using the WatermarkContent Property
In scenarios, where you want to show custom content, when an empty string is entered, you need to use the WatermarkContent property.
In the following example, the user is asked to enter four digits:
CopyXAML
<telerik:RadWatermarkTextBox x:Name="radWatermarkTextBox" WatermarkContent="Please Enter Four Digits:" />
The WatermarkContent property is of type object. Which means that you can set anything you want. For example:
CopyXAML
<telerik:RadWatermarkTextBox x:Name="radWatermarkTextBox">
<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>
Using WatermarkTemplate Property
Similarly, you can use the WatermarkTemplate property for the same sort of scenarios. Note that in this case you should define a new DataTemplate for the WatermarkTemplate property.
CopyXAML
<telerik:RadWatermarkTextBox x:Name="radWatermarkTextBox">
<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>
Setting the SelectionOnFocus Property
The SelectionOnFocus property of RadWatermarkTextBox allows you to specify what will happen with the cursor when the control gets focus. In the following example the SelectionOnFocus property is set to SelectAll. Once the RadWatermarkTextBox gets focused, it will select its whole text.
CopyXAML
<telerik:RadWatermarkTextBox x:Name="radWatermarkTextBox"
SelectionOnFocus="SelectAll"
WatermarkContent="Please Enter Four Digits:" />