WPF TextBlock highlight certain parts based on search condition

后端 未结 9 1144
遇见更好的自我
遇见更好的自我 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 08:57

    If you are handling ContainerContentChanging for your ListViewBase, you can take the following approach: TextBlock highlighting for WinRT/ContainerContentChanging

    Please note that this code is for Windows RT. The WPF syntax will be slightly different. Also note that if you are using binding to populate the TextBlock.Text property, the text generated by my approach will be overwritten. I use ContainerContentChanging to populate target fields because of radically-increased performance and improvements in memory usage, vs. normal binding. I use binding only to manage the source data, not the data view.

提交回复
热议问题