突出显示WPF列表视图中的搜索文本 [英] Highlight searched text in WPF listview

查看:79
本文介绍了突出显示WPF列表视图中的搜索文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。



我正在编写代码在WPF中使用ListView突出搜索文本。



问题是,当我搜索一个特定的单词时,只有屏幕上可见的匹配单词才会被突出显示,但是其他单词在



listviewItems中应该突出显示位于列表视图的底部未突出显示。



运行程序后,我手动向下滚动到列表视图的底部,当我搜索单词时,它运行良好。



我尝试了什么:



为了解决这个问题,我添加了如下代码。 Listview向下和向上滚动,就像我想要的那样,但listItems仍然没有突出显示。



//滚动到列表底部以确保每个项目都在视图中

if(listview.Items.Count> 1)listview.ScrollIntoView(listview.Items [listview.Items.Count - 1]);



//滚动回顶部以确保一切正常

if(listview.Items.Count> 1)listview.ScrollIntoView (listview.Items [0]);

Hello.

I am writing code Highlight Searched Text with ListView in WPF.

The problem is that when I search a specific word, only match words in the screen visible are hightlighted but the other words in

listviewItems that should be highlighted which are located in the bottom of the listview are not highlighted.

After I run the program and I scroll down manually to the bottom in the list view and when I search the word, then it works well.

What I have tried:

To solve the problem, I added the code like below. Listview scrolls down and up properly like I intented to but the listItems does not highlight still.

// scroll to bottom for the list to make sure every item is in the view
if (listview.Items.Count > 1) listview.ScrollIntoView(listview.Items[listview.Items.Count - 1]);

// scroll back to top to make sure everything looks correct
if (listview.Items.Count > 1) listview.ScrollIntoView(listview.Items[0]);

推荐答案

这是本月的一篇文章,它将满足您的要求; WPF TextBlock荧光笔 [ ^ ]
Here is an article from this month that will do what you are asking for; WPF TextBlock Highlighter[^]


这篇关于突出显示WPF列表视图中的搜索文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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