Click here to Skip to main content
15,846,038 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

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]);
Updated 27-Feb-18 21:00pm

1 solution

Here is an article from this month that will do what you are asking for; WPF TextBlock Highlighter[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900