How to change the DatePicker_WatermarkText

Oct 29, 2008 at 10:39 AM
Hi,

On the DatePicker control, I allready changed the current thread culture so that the months and week days appear on the language I want. 
Even so, I'm still getting the "Show Calendar" message when no date is selected.
I allready found that the message is defined in the ExceptionStringTable.txt file.

My question is: Is there any way to change the string using only the binary files or do I have to change the source code?

Tks
Oct 29, 2008 at 9:19 PM

Unfortunately, there is no public assessor for Watermark Text in Date Picker. This feature needs to be added to Date Picker control.

Oct 31, 2008 at 10:33 AM
Hi Lena,
do you know when it will be added? I've the same problem.
Tks.
Oct 31, 2008 at 8:00 PM
There is no way to remove the original Watermark Text now or set to another text that you want to replace the original one. I would consider this as bug and ask team developers to fix it.
  Thanks. Lena
Aug 25, 2009 at 2:37 PM

Some people are recompiling the WPFToolkit source code, adding  the property Watermark.

I came up with an extension:

 

public sealed class DateBox : DatePicker
    {
        public static readonly System.Windows.DependencyProperty CustomWatermarkProperty = System.Windows.DependencyProperty.Register("Watermark", typeof(string), typeof(DateBox), new System.Windows.PropertyMetadata(""));

        public string CustomWatermark
        {
            get { return (string)GetValue(CustomWatermarkProperty); }
            set { SetValue(CustomWatermarkProperty, value); }
        }

        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);
            FieldInfo fiTextBox = typeof(DatePicker).GetField("_textBox", BindingFlags.Instance | BindingFlags.NonPublic);
            if (fiTextBox != null)
            {
                DatePickerTextBox dateTextBox = (DatePickerTextBox)fiTextBox.GetValue(this);
                PropertyInfo piWatermark = typeof(DatePickerTextBox).GetProperty("Watermark", BindingFlags.Instance | BindingFlags.NonPublic);
                if (piWatermark != null)
                {
                    piWatermark.SetValue(dateTextBox, this.CustomWatermark, null);
                }
            }
        }
    }

 

 

 

    public sealed class DateBox : DatePicker
    {
        public static readonly System.Windows.DependencyProperty CustomWatermarkProperty = System.Windows.DependencyProperty.Register("Watermark", typeof(string), typeof(DateBox), new System.Windows.PropertyMetadata(""));
        public string CustomWatermark
        {
            get { return (string)GetValue(CustomWatermarkProperty); }
            set { SetValue(CustomWatermarkProperty, value); }
        }
        protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);
            FieldInfo fiTextBox = typeof(DatePicker).GetField("_textBox", BindingFlags.Instance | BindingFlags.NonPublic);
            if (fiTextBox != null)
            {
                DatePickerTextBox dateTextBox = (DatePickerTextBox)fiTextBox.GetValue(this);
                PropertyInfo piWatermark = typeof(DatePickerTextBox).GetProperty("Watermark", BindingFlags.Instance | BindingFlags.NonPublic);
                if (piWatermark != null)
                {
                    piWatermark.SetValue(dateTextBox, this.CustomWatermark, null);
                }
            }
        }
    }

and in XAML:

 

 

<UserControl x:Class="MyAssembly.MyForm"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     Width="1088"
    xmlns:myControls="clr-namespace:MyAssembly.MyControls;assembly=MyAssembly.MyControls" ....>

<myControls:DateBox Height="25" Margin="532,221,411.94,0" Name="dtpEnterDate" VerticalAlignment="Top" xml:lang="en-UK" CustomWatermark="Hehehe"/>