DotNetKit.Wpf.AutoCompleteComboBox
DotNetKit.Wpf.AutoCompleteComboBox copied to clipboard
Feature request: customize suggestions order
vain0, thank you for this piece of code. ComboBox is brilliant and perfectly works out-of-box.
I offer to improve suggestions orger. For example:
Text input: it
Current result:
git
item
iterate
community
Result requested: strings starting with it placed on the top of list:
item
iterate
git
community
Is there a way to add such tweak?
Hello. Your suggestion looks good! Thank you.
Take a look:
public virtual Func<object, bool> GetFilter(string query, Func<object, string> stringFromItem)
{
return item =>
//! Filter one
stringFromItem(item).IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0 ||
//! Filter two
stringFromItem(item).IndexOf(Transliteration.LatinToCyrillyc(query, Language.Russian),
StringComparison.OrdinalIgnoreCase) >= 0;
}
Here we got 2 filters.
Replacing Func<object, bool> GetFilter with List<Func<object, bool>> GetFilters gives us possibility to order results by filters.
I think GetFilters is not flexible. It can be generalized to:
public virtual Func<object, double> Priority(string query, Func<object, string> text)
{
return item =>
{
if (filter1(query, text)(item)) return 0;
if (filter2(query, text)(item)) return 1;
return double.MaxValue;
};
}
I'm facing a problem that there is no way to sort Items, the backing collection of the dropdown list, with an arbitrary comparer. We need to sort items by properties with default comparers; or sort ItemsSource instead. So there are two options:
- (A) Sort items by a property. Update the property's value as necessary for ordering.
- (B) Ask users to provide a command to sort
ItemsSource.
I don't choose (A) because it's inefficient and difficult to use. I have hesitation in implementing (B). Hmm...
I'm sorry, but I can't dig deep into AutoCompleteComboBox mechanics and help with this feature right now.