Watermark / hint text / placeholder TextBox

后端 未结 30 3105
遇见更好的自我
遇见更好的自我 2020-11-22 02:20

How can I put some text into a TextBox which is removed automatically when user types something in it?

30条回答
  •  面向向阳花
    2020-11-22 02:20

    There is an article on CodeProject on how to do it in "3 lines of XAML".

    
      
      
    
    

    Ok, well it might not be 3 lines of XAML formatted, but it is pretty simple.

    One thing to note though, is that it uses a non-standard extension method on the Text property, called "IsEmpty". You need to implement this yourself, however the article doesn't seem to mention that.

提交回复
热议问题