XAML only WPF Watermarked TextBox
2016-08-23
0 0 0
4.0
Other
Earn points
Translated by maninwest@Codeforge Author:MatthewThomas@CodeProject
A lot of the examples I found on how to add a watermark to a TextBox involve a significant amount of code-behind, handling text changed events, or making use of a customIValueConverterorIMultiValueConverter. In this article, I'll show how to add a watermark to a TextBox by only using XAML markup.
Background
A demonstration project I recently worked on was pre-setting the text of a textbox as kind of a poor-man's watermark. But when you started typing in the box, you have to first clear away the default value. That's not a watermark, that's just annoying. I wanted to fix this, but I didn't want to write a bunch of C# code to make it happen. I knew it could be done in XAML.
Using the code
Let's just jump right to it
A lot of the examples I found on how to add a watermark to a TextBox involve a significant amount of code-behind, handling text changed events, or making use of a customIValueConverterorIMultiValueConverter. In this article, I'll show how to add a watermark to a TextBox by only using XAML markup.
Background
A demonstration project I recently worked on was pre-setting the text of a textbox as kind of a poor-man's watermark. But when you started typing in the box, you have to first clear away the default value. That's not a watermark, that's just annoying. I wanted to fix this, but I didn't want to write a bunch of C# code to make it happen. I knew it could be done in XAML.
Using the code
Let's just jump right to it
c#
wpf
xaml
文本
水印
Related Source Codes
No. 186: DX0110- Source code for community propert
0
0
no vote
No. 219: DX0149- Source code for community propert
0
0
no vote
Verification code identification
0
0
no vote
CSV data analysis tool
0
0
no vote
Source code of hospital medical record information
0
0
no vote
No comment