DatePickerTextBox.Watermark Property

Silverlight

Gets or sets the content displayed as a watermark in the DatePickerTextBox when it is empty.

Namespace:  System.Windows.Controls.Primitives
Assembly:  System.Windows.Controls (in System.Windows.Controls.dll)

public Object Watermark { get; set; }
<controlsPrimitives:DatePickerTextBox>
  <controlsPrimitives:DatePickerTextBox.Watermark>
    singleUIElement
  </controlsPrimitives:DatePickerTextBox.Watermark>
</controlsPrimitives:DatePickerTextBox>
<controlsPrimitives:DatePickerTextBox Watermark="uistring"/>

XAML Values

singleUIElement

A single UIElement (such as Path or Image) that displays the intended watermark content.

uistring

A string that provides the watermark content.

Property Value

Type: System.Object
The content displayed as a watermark in the DatePickerTextBox when it is empty.

The Watermark property detects whether the DatePicker format is set to Long or Short and provides the correct long or short format hint to the user.

The following examples show how to change the watermark value displayed in a DatePicker control by deriving from DatePicker, retrieving the textbox part and setting its Watermark property. This change only affects the empty DatePicker, before a date is selected. Once a date is selected the date is then removed, the DatePicker reverts to the default behavior of either a long or short format hint.

Run this sample


// Create a class that inherits from DatePicker.
public class MyDatePicker : DatePicker
{
  // Override OnApplyTemplate to retrieve the DatePickerTextBox part of the template.
    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();
        DatePickerTextBox box = base.GetTemplateChild("TextBox") as DatePickerTextBox;

        string formatString = "";
        if (this.SelectedDateFormat == DatePickerFormat.Short)
            formatString = "mm/d/yy";
        if (this.SelectedDateFormat == DatePickerFormat.Long)
            formatString = "dddd, MMMM, dd, yyyy";

        // Set the Watermark property.
        box.Watermark = "Type ( " + formatString + " or select a date --> ";
    }
}


The following XAML shows how to use the derived DatePicker in a page.


    <UserControl x:Class="DatePickerWatermarkVB.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local ="clr-namespace:DatePickerWatermarkVB"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400" 
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">
    <Grid x:Name="LayoutRoot" Background="White">
        <local:MyDatePicker Width="240" Height="30" />
    </Grid>
</UserControl>


Silverlight

Supported in: 5, 4, 3

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show: