如何在 WPF 中实现搜索框的默认文本? [英] How do you implement default text for a search box in WPF?

查看:29
本文介绍了如何在 WPF 中实现搜索框的默认文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现类似于更改搜索中的默认文本Box" 用于 WPF 搜索文本框.该框应在为空时显示一些灰色的搜索.."文本,然后在输入文本时应正常运行.链接的文章显示了如何在 javascript 中执行此操作.在 WPF 中如何开始这条道路?到目前为止,我的最佳想法是在主文本框之上的另一个文本框,只要搜索文本框获得焦点或文本,它就会变得不可见.

I want to implement something exactly like "Changing the Default Text in the Search Box" for a WPF search TextBox. The box should show some greyed out "Search.." text when it's empty, and then it should function normally when text is typed in. The linked article shows how to do this in javascript. How would one start down this path in WPF? The best idea I've had so far is another text box on top of the main one that goes invisible whenever the search textbox gets focus or text.

推荐答案

试试 Kevin Moore 的 Bag-o-Tricks 中的 InfoTextBox 示例.你可以从http://work.j832.com/2008/01/real-update-to-bag-o-tricks.html

Try the InfoTextBox sample from Kevin Moore's Bag-o-Tricks. You can download it from http://work.j832.com/2008/01/real-update-to-bag-o-tricks.html

这篇关于如何在 WPF 中实现搜索框的默认文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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