窗口的 WPF 通用搜索框(仅视图搜索,无后端搜索)
我正在考虑实现通用视图搜索的方法。我这里的意思是说一个窗口有很多控件(包括用户控件、自定义控件等)。我想在窗口顶部实现一个通用搜索框,用于搜索窗口中的任何文本并突出显示它们。
我想知道是否有一种通用的方法可以做到这一点,或者是否有人尝试过这种基于 UI 的搜索。
我在互联网上进行搜索,发现了一些不错的链接,如下所示::
http://khason.net/blog/ search-and-highlight-any-text-on-wpf-rendered-page/ 表示搜索并突出显示 WPF 渲染页面中的任何文本,但当有大量 UserControls 和 CustomControls 时它不起作用。
- < p>我自己做了一些研究并考虑过 VisualTree,LogicalTree 等,但我没有发现它们令人满意。
有人说使用附加行为或数据绑定来做到这一点,但这也对我没有帮助。因为即使我使用这种技术实现了搜索,问题还是突出。假设有 4 个具有不同背景颜色的 TextBox,当找到 Text 时我将背景突出显示为黄色,当未找到 Text 时我无法删除突出显示,因为我不知道 TextBox 以前的背景颜色。
好吧,我的想法已经够多了。我愿意简单地接受我的想法不会有任何进展。所以我想要一些关于实现 UI 搜索的指导。另外,如果你们能告诉我如何使其通用,那将会很有用!
I was thinking of ways to implement a generic View search. What I mean here is say a Window has many controls (including usercontrols,customcontrols, etc). I want to implement a generic search box on the top of window which searches any Text in the window and highlight them.
I wanted to know is there a generic way of doing this or has anyone tried such UI based search.
I was searching through internet and found some nice links like below::
http://khason.net/blog/search-and-highlight-any-text-on-wpf-rendered-page/ which says search and highlight any Text in WPF rendered page but it doesnt work when there are lot of UserControls and CustomControls.
I myself did some research and thought of going through the VisualTree,LogicalTree, etc but I did not find them satisfactory.
Some say do it using attached behaviors or by data binding but that also did not help me. Because even if i achieved search using this technique, the problem is highlighting. Say there are 4 TextBoxes having different background colors and I highlight background to Yellow when Text is found, I have no way of removing the highlighting when Text is not found because I don't know the previous background color of TextBox.
Ok , enough of my thoughts. I would like to simply accept I am going nowhere in my thoughts. So people I want some guidance in implementing UI search. Also if you people can tell me how I can make it generic, it will be useful!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论