I need a way to highlight text in a text block or silverlight text box. This is done to highlight search results, for example, if you try to press Ctrl + F in your browser and find a word, the browser will highlight matching words.
In a text block you can use Runto highlight words, for example: -
Run
<TextBlock>Ordinary Text <Run Foreground="Red">Highlighted Text</Run> More Ordinary Text</TextBlock>
Xml , , , Xaml ( XML) < , > .
<
>
Silverlight. , .
WRONG
:
private void Find(RichTextBox richTextBox, string term) { var builder = new StringBuilder(); var inlines = richTextBox.Blocks .OfType<Paragraph>() .SelectMany(paragraph => paragraph.Inlines); foreach( var inline in inlines ) { builder.Append(((Run)inline).Text); } var regex = new Regex(term); var matchedStrings = regex.Matches(builder.ToString()); foreach( var item in matchedStrings ) { // Whatever you want to do. } }
Source: https://habr.com/ru/post/1792472/More articles:How to get SOAP response when an exception occurs? - soapHow can I set the differnt font to UIButton dynamically? - iphoneAndroid Neon Tubing - android.gitconfig. How to protect? - gitDrawing a bitmap on canvas has become scaled - androidScrapy: connection refused - pythonYahoo Finance API - yahoo-financeПрограммное обеспечение для генерации PHP-классов из диаграммы классов UML - objectC # - Ftp protocol implementation - c #corporate library not registering - loggingAll Articles