在纯 XAML 中创建 WPF 水印 [英] Create WPF Watermark in Pure XAML

查看:27
本文介绍了在纯 XAML 中创建 WPF 水印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是用于登录屏幕上的 TextBox 控件,其中 TextBox 包含用户名.我希望 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".

当单击 TextBox 时,我希望将内容设置为"IE;什么都没有(除非用户已经编辑了内容).

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).

这是当今非常标准的功能,类似于wordpress login(在页面顶部).恐怕没有比这更好的例子了:)

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 :)

所以,无论如何,我已经使用 ViewModel 完成了此操作,并且效果很好,但我想知道这是否可以完全从 XAML 端完成.不关心业务逻辑,所以我认为没有 VM 会更好.

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.

http://bendewey.wordpress.com/2008/09/27/wpf-shadowed-textbox-watermark/

http://www.c-sharpcorner.com/uploadfile/rahul4_saxena/watermark-textbox-in-wpf/

http://www.codeproject.com/Articles/26977/A-WatermarkTextBox-in-3-lines-of-XAML

这篇关于在纯 XAML 中创建 WPF 水印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆