DotNetKit.Wpf.AutoCompleteComboBox icon indicating copy to clipboard operation
DotNetKit.Wpf.AutoCompleteComboBox copied to clipboard

Feature request: customize suggestions order

Open AsValeO opened this issue 8 years ago • 4 comments

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?

AsValeO avatar Jun 26 '17 07:06 AsValeO

Hello. Your suggestion looks good! Thank you.

vain0x avatar Jun 29 '17 12:06 vain0x

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.

AsValeO avatar Jun 30 '17 07:06 AsValeO

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...

vain0x avatar Jul 06 '17 15:07 vain0x

I'm sorry, but I can't dig deep into AutoCompleteComboBox mechanics and help with this feature right now.

AsValeO avatar Jul 08 '17 19:07 AsValeO