RadControls for Silverlight

You can set a watermark content to the RadMaskedTextBox by using the EmptyContent and EmptyContentTemplate properties. When the Value of the RadMaskedTextBox is null or empty the EmptyContent will be displayed.

Using EmptyContent Property

In scenarios, where you want to show custom content, when an empty string is entered, you need to use the EmptyContent property.

In the following example, the user is asked to enter four digits:

CopyXAML
<telerik:RadMaskedTextBox x:Name="radMaskedTextBox" 
                          Mask="0000"
                          MaskType="Standard" />

When an empty string is entered, then the default Placeholder (the character used to represent the absence of user input in RadMaskedTextBox)will be displayed.

If the EmptyContent property is set, then it will be displayed when an empty string is entered.

CopyXAML
<telerik:RadMaskedTextBox x:Name="radMaskedTextBox" 
                          EmptyContent="Please Enter Four Digits"
                          Mask="0000"
                          MaskType="Standard" />

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

CopyXAML
<telerik:RadMaskedTextBox x:Name="radMaskedTextBox" 
                          Mask="0000"
                          MaskType="Standard">
    <telerik:RadMaskedTextBox.EmptyContent>
        <telerik:RadWatermarkTextBox Margin="3,0,0,0">
            <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>
    </telerik:RadMaskedTextBox.EmptyContent>
</telerik:RadMaskedTextBox>

Using EmptyContentTemplate Property

Similarly, you can use the EmptyContentTemplate property for the same sort of scenarios. Note that in this case you should define a new DataTemplate for the EmptyContentTemplate property.

CopyXAML
<telerik:RadMaskedTextBox x:Name="radMaskedTextBox" 
                          Mask="0000"
                          MaskType="Standard">
    <telerik:RadMaskedTextBox.EmptyContentTemplate>
        <DataTemplate>
            <telerik:RadWatermarkTextBox Margin="3,0,0,0">
                <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>
        </DataTemplate>
    </telerik:RadMaskedTextBox.EmptyContentTemplate>
</telerik:RadMaskedTextBox>

Tip
You can see a live demo demonstrating the EmptyContent property here.
Tip
For more information about the RadWatermarkTextBox control, check out the Working with RadWatermarkTextBox topic.

See Also