Edit this page

Features

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.

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:

[XAML] Example 1: Setting the WatermarkContent property

<telerik:RadWatermarkTextBox x:Name="radWatermarkTextBox" WatermarkContent="Please Enter Four Digits:" />

radwatermarktextbox overview 010

The WatermarkContent property is of type object. Which means that you can set anything you want. For example:

[XAML] Example 2: 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>

radwatermarktextbox overview 020

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.

[XAML] Example 3: 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>

radwatermarktextbox overview 030

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.

[XAML] Example 4: Setting the SelectionOnFocus property

<telerik:RadWatermarkTextBox x:Name="radWatermarkTextBox3" 
                             SelectionOnFocus="SelectAll"
                             WatermarkContent="Please Enter Four Digits:" />

WatermarkBehavior

WatermarkBehavior is an enumeration property which specifies when the watermark content of RadWatermarkTextBox will be hidden. It could receive the following values:

  • HiddenWhenFocused - The watermark will be hidden when the RadWatermarkTextBox receives focus
  • HideOnClick - The watermark will be hidden when the the user clicks on the RadWatermarkTextBox
  • HideOnTextEntered - The watermark will be hidden when the the user writes text into the RadWatermarkTextBox

The default value is HideOnTextEntered.

See also

Overview