Ponraja
Ponraja

Reputation: 570

camel case search in WPF AutoCompleteBox

How implement camel case search (search words with capital letters) in WPF AutoCompleteBox. Example: consider my items source contains "Phone Number" then if we type "pn" in text box it suggest phone number in drop down.

Upvotes: 0

Views: 671

Answers (2)

Mat J
Mat J

Reputation: 5632

You can set the FilterMode to custom and set a ItemFilter predicate to something similar to:

autoBox.FilterMode = AutoCompleteFilterMode.Custom;
autoBox.ItemFilter = new AutoCompleteFilterPredicate<object>((searchText, obj) => 
                    (obj as string).Where(x=>Char.IsUpper(x))
                                   .SequenceEqual(searchText.ToUpper()));

Upvotes: 0

alan7678
alan7678

Reputation: 2311

Set the item filter property as described here, there is an example at the bottom.

You can implement your logic like they have implemented the function SearchEmployees.

Simply add a check if a string contains an upper case letter of the input return true else return false.

https://msdn.microsoft.com/en-us/library/system.windows.controls.autocompletebox.itemfilter(v=vs.95).aspx

Upvotes: 1

Related Questions