I want to highlight some lines in a textblock. These lines are decided dynamically. How do I do it? For eg- I want to highlight all the lines containing files tag, how do I do it?
Something like the following should work for you:
foreach(System.Windows.Documents.Run run in textBlock.Inlines.OfType<System.Windows.Documents.Run>())
{
if (run.Text.Contains("<files ") || run.Text.Contains("</files>"))
{
run.Background = Brushes.Yellow;
}
}
You can could also use regular expressions to do the matching instead of text compares if you need more flexibility.