How can I put some text into a textbox which is removed automatically when user types something in it? (In WPF)
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Carriage Return (ASCII chr 13) is missing from tex
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
I found this way to do it in a very fast and easy way
Maybe it can help to anyone trying to do this
Source: http://www.admindiaries.com/displaying-a-please-select-watermark-type-text-in-a-wpf-combobox/
My solution is quite simple.
In my login window. the xaml is like this.
the code is like this.
Just decide to hide or show the watermark textbox is enough. Though not beautiful,but work well.
Look at another simple solotion:
I'm focused GotFocus and LostFocus events.
XAML:
C#:
Add mahapps.metro to your project. Add textbox with the above code to the window.
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.