|
1 | | -# How to search and highlight item in TreeViewAdv? |
2 | | -This example demonstrates how to search and highlighted the item of TreeViewAdv control in WPF platform. |
| 1 | +# How to search and highlight item in TreeViewAdv |
| 2 | + |
| 3 | +This example demonstrates how to search and highlighted the item of `TreeViewAdv` control in WPF platform. |
3 | 4 |
|
4 | 5 | # About Sample |
5 | 6 |
|
6 | | -This sample provides the demo on how to search and highlight the text in TreeViewAdv. |
| 7 | +This sample provides the demo on how to search and highlight the text in `TreeViewAdv`. |
| 8 | + |
| 9 | +To search and highlight the item in `TreeViewAdv`, Search method has been implemented which is used to compare the search text with model items. Highlighted the matched text in TextBlock inside the `TreeViewItemAdv`. |
| 10 | + |
| 11 | +``` c# |
| 12 | +if (mainitem != null && MatchSearchText(model.Header)) |
| 13 | +{ |
| 14 | + //Function which is used to apply inline to the TextBlock |
| 15 | + ApplyInline(mainitem, false); |
| 16 | +} |
| 17 | +``` |
| 18 | + |
| 19 | +Options like Search, FindPrevious, Find Next, SearchType (Contains, EndsWith, StartsWith options) has been used to match search text using ApplyInline method and apply the SearchBrush for highlighting the search text. |
| 20 | + |
| 21 | +``` c# |
| 22 | +if (!string.IsNullOrEmpty(tempSearchText)) |
| 23 | + { |
| 24 | + if (this.SearchType == SearchType.StartsWith) |
| 25 | + { |
| 26 | + if (!(bool)CaseSensitiveSearchCheckBox.IsChecked) |
| 27 | + regex = new Regex("^(" + tempSearchText + ")", RegexOptions.IgnoreCase); |
| 28 | + else |
| 29 | + regex = new Regex("^(" + tempSearchText + ")", RegexOptions.None); |
| 30 | + } |
| 31 | + else if (this.SearchType == SearchType.EndsWith) |
| 32 | + { |
| 33 | + if (!(bool)CaseSensitiveSearchCheckBox.IsChecked) |
| 34 | + regex = new Regex("(" + tempSearchText + ")$", RegexOptions.IgnoreCase); |
| 35 | + else |
| 36 | + regex = new Regex("(" + tempSearchText + ")$", RegexOptions.None); |
| 37 | + } |
| 38 | + else |
| 39 | + { |
| 40 | + if (!(bool)CaseSensitiveSearchCheckBox.IsChecked) |
| 41 | + regex = new Regex("(" + tempSearchText + ")", RegexOptions.IgnoreCase); |
| 42 | + else |
| 43 | + regex = new Regex("(" + tempSearchText + ")", RegexOptions.None); |
| 44 | + } |
| 45 | +} |
| 46 | +``` |
0 commit comments