WPF TextBlock highlight certain parts based on search condition

后端 未结 9 1156
遇见更好的自我
遇见更好的自我 2020-12-01 08:42

I have TextBlock that has Inlines dynamicly added to it (basically bunch of Run objects that are either italic or bold).

In my application I have search function.

9条回答
  •  误落风尘
    2020-12-01 09:11

    This question is similar to How to display search results in a WPF items control with highlighted query terms

    In answer to that question, I came up with an approach that uses an IValueConverter. The converter takes a text snippet, formats it into valid XAML markup, and uses a XamlReader to instantiate the markup into framework objects.

    The full explanation is rather long, so I've posted it to my blog: Highlighting Query Terms in a WPF TextBlock

提交回复
热议问题