I created my own text block that will help you highlight a piece of text in the text value of a TextBlock.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; namespace UI.WPF.UserControls { class CustomTextBlock:TextBlock { string _originalText; public string HighlighText { get { return (string)GetValue(HighlighTextProperty); } set { SetValue(HighlighTextProperty, value); RenderHighlightedText(); } }
Method of use.
<usercontrol:CustomTextBlock Text="{Binding Title}" HighlighText="{Binding DataContext.SearchText, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Page}}}" />
For more information
https://sites.google.com/site/greateindiaclub/mobil-apps/windows8/highlightpartoftextinwpftextblockcontrol
source share