Urgent help - I have to implement Search functionality in WPF windows application. In this application, I have a TreeView control, when the user clicks on any TreeViewnode corresponding Wpf user control will appear in right side with data.
I want to implement search. User can enter any thing into Search textbox and that search term should get highlighted in rightside WPF 开发者_如何转开发user control.
How can I implement that?
Is there way to show searched term without hitting database.
Your help is much appreciated.
1) To search any textual item in a WPF view you would have get into the logical and visual tree to get children.
2) Identify the textual properties of each child such as .Text, .Content, .Header.
if an item that carries texual info is found then use
if (<value> is string && ((string)<value>).Contains(searchString))
{
/// Implement step 3 and 4 below.
}
3) Use child.Focus() and child.BringIntoView() calls if one by one search is intended. Otherwise skip to step 4.
4) Use adorners to highlight such item.
Sadly this search will have to be carried using Dispatcher.BeginInvoke()
and may hang the view if lots of visual items exist.
精彩评论