开发者

WPF windows application - Search

开发者 https://www.devze.com 2023-04-11 14:22 出处:网络
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 contr

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号