创建WPF水印纯XAML [英] Create WPF Watermark in Pure XAML
问题描述
这是一个登录屏幕上一个TextBox控件,其中包含文本框的用户名。我想文本框以下列方式进行:
This is for a TextBox control on a login screen, where the TextBox contains the username. I want the TextBox to perform in the following way:
-
在内容为空的内容应设置为用户名。
When the content is empty the content should be set to "Username".
在点击文本框我想要的内容设置为
即;无关(除非内容已经被用户编辑)
When the TextBox is clicked I want the content to be set to "" i.e; nothing (unless the content has already been edited by the user).
这是一个pretty标准功能的今天,这样的事情字preSS登录(在页面顶部)。的 coudn't想到一个更好的例子比这恐怕:)的
This is a pretty standard feature nowadays, something like this wordpress login (at the top of page). coudn't think of a better example than this I'm afraid :)
所以,无论如何,我已经做到了这一点使用视图模型和它的作品很好,但我想知道这是可以做到的单纯从XAML结束。没有业务逻辑来讲,所以我认为这将是更好地做没有虚拟机。
So, anyway, I've already done this using a ViewModel and it works well, but I'd like to know if this can be done purely from the XAML end. No business logic is concerned so I think it would be better to do it without the VM.
推荐答案
查找下面的示例帮助你找到自己的方式。
Find the below samples help you to find your way.
<一个href=\"http://bendewey.word$p$pss.com/2008/09/27/wpf-shadowed-textbox-watermark/\">http://bendewey.word$p$pss.com/2008/09/27/wpf-shadowed-textbox-watermark/
<一个href=\"http://www.c-sharpcorner.com/uploadfile/rahul4_saxena/watermark-textbox-in-wpf/\">http://www.c-sharpcorner.com/uploadfile/rahul4_saxena/watermark-textbox-in-wpf/
<一个href=\"http://www.$c$cproject.com/Articles/26977/A-WatermarkTextBox-in-3-lines-of-XAML\">http://www.$c$cproject.com/Articles/26977/A-WatermarkTextBox-in-3-lines-of-XAML
这篇关于创建WPF水印纯XAML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!