Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7736889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:51:28+00:00 2026-06-01T07:51:28+00:00

While browsing MSDN documentation, you may come across this gem: TextBox.Watermark. Awesome! I’ve been

  • 0

While browsing MSDN documentation, you may come across this gem: TextBox.Watermark.

“Awesome! I’ve been wanting a built-in way to do watermarking on my text boxes! This is great, let me go ahead and set that in XAML!”

<TextBox Watermark="This is my watermark" Margin="20"></TextBox>

Unfortunately, if you run this you won’t get what you expect:

enter image description here

And the detail:
enter image description here

What is this? Well, look at the MSDN documentation closely:
enter image description here

That’s right. It’s supported in Silverlight 4, but it also says “Do not use in a Silverlight 4 application”. If you do use it, you receive a System.NotImplemented exception. To verify, here is the code for the property decompiled via Reflector:

[EditorBrowsable(EditorBrowsableState.Never)]
public object Watermark
{
get
{
StubHelper.ThrowIfNotInDesignMode();
return base.GetValue(WatermarkProperty);
}
set
{
StubHelper.ThrowIfNotInDesignMode();
base.SetValue(WatermarkProperty, value);
}
}

There it is – it throws an exception any time it’s not in design mode. This makes no sense right? Why would Microsoft do this?

Unfortunately I haven’t found any definitive answer yet, however if I had to guess it’s because Microsoft is planning on implementing a Watermark behavior on the TextBox control in a future version (perhaps v5) and wanted to effectively reserve this property so third party control creators don’t subclass TextBox and create their own Watermark property.
I know of at least one control vendor, ComponentOne, who has a control that inherits from TextBox and provides a Watermark property.
To me, it seems this is Microsoft’s way of discouraging people from using this property name on their own TextBox subclasses.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T07:51:29+00:00Added an answer on June 1, 2026 at 7:51 am

    Create One Class library project . Add Class File use the Following code …..After that Add The In this dll In Your Project.

    public class WatermarkTextBox : TextBox 
    { 
        private bool displayWatermark = true; 
        private bool hasFocus = false; 
         public WatermarkTextBox() 
        { 
            this.GotFocus += new RoutedEventHandler(WatermarkTextBox_GotFocus); 
            this.LostFocus += new RoutedEventHandler(WatermarkTextBox_LostFocus); 
            this.TextChanged += new TextChangedEventHandler(WatermarkTextBox_TextChanged); 
            this.Unloaded += new RoutedEventHandler(WatermarkTextBox_Unloaded); 
        } 
    
        private void WatermarkTextBox_TextChanged(object sender, TextChangedEventArgs e) 
        { 
            if (!hasFocus && Text == "") 
            { 
                setMode(true); 
                displayWatermark = true; 
                this.Text = Watermark; 
            } 
        } 
    
        private void WatermarkTextBox_Unloaded(object sender, RoutedEventArgs e) 
        { 
            this.GotFocus -= WatermarkTextBox_GotFocus; 
            this.LostFocus -= WatermarkTextBox_LostFocus; 
            this.Unloaded -= WatermarkTextBox_Unloaded; 
            this.TextChanged -= WatermarkTextBox_TextChanged; 
        } 
    
        private void WatermarkTextBox_GotFocus(object sender, RoutedEventArgs e) 
        { 
            hasFocus = true; 
            if (displayWatermark) 
            { 
                setMode(false); 
                this.Text = ""; 
            } 
        } 
        private void WatermarkTextBox_LostFocus(object sender, RoutedEventArgs e) 
        { 
            hasFocus = false; 
            if (this.Text == "") 
            { 
                displayWatermark = true; 
                setMode(true); 
                this.Text = Watermark; 
            } 
            else 
            { 
                displayWatermark = false; 
            } 
        } 
        private void setMode(bool watermarkStyle) 
        { 
            if (watermarkStyle) 
            { 
                this.FontStyle = FontStyles.Italic; 
                this.Foreground = new SolidColorBrush(Colors.Gray); 
            } 
            else 
            { 
                this.FontStyle = FontStyles.Normal; 
                this.Foreground = new SolidColorBrush(Colors.Black); 
            } 
        } 
        public new string Watermark 
        { 
            get { return GetValue(WatermarkProperty) as string; } 
            set { SetValue(WatermarkProperty, value); } 
        } 
        public static new readonly DependencyProperty WatermarkProperty = 
            DependencyProperty.Register("Watermark", typeof(string), typeof(WatermarkTextBox), new PropertyMetadata(watermarkPropertyChanged)); 
        private static void watermarkPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) 
        { 
            WatermarkTextBox textBox = obj as WatermarkTextBox; 
            if (textBox.displayWatermark) 
            { 
                textBox.Text = e.NewValue.ToString(); 
                textBox.setMode(true); 
            } 
        } 
    

    XAML:

      xmlns:watertext="clr-namespace:SilverlightClassLibrary1;assembly=SilverlightClassLibrary1"
    
    
        <watertext:WatermarkTextBox Watermark="WElcome" Margin="150,115,120,166"></watertext:WatermarkTextBox>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While browsing I came across this blog post about using the Wikipedia API from
While browsing some source code I came across a function like this: void someFunction(char
I came across this presentation while browsing SO some time ago, and it relates
I am using this IP Validation Function that I came across while browsing, it
While browsing some code, I came across this line: if False: #shedskin I understand
Came across this one while browsing the response to another question on SO (
While browsing the MSDN documentations on Equals overrides, one point grabbed my attention. On
While browsing System.Zip (Delphi XE2) to see how it works, I found this function:
While browsing the code of an erlang application, I came across an interesting design
While browsing the Caml Light library for programming examples, I stumbled across the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.