Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: customize suggestions order #2

Open
AsValeO opened this issue Jun 26, 2017 · 4 comments
Open

Feature request: customize suggestions order #2

AsValeO opened this issue Jun 26, 2017 · 4 comments

Comments

@AsValeO
Copy link

AsValeO commented Jun 26, 2017

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?

@vain0x
Copy link
Owner

vain0x commented Jun 29, 2017

Hello. Your suggestion looks good! Thank you.

@AsValeO
Copy link
Author

AsValeO commented Jun 30, 2017

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.

@vain0x
Copy link
Owner

vain0x commented Jul 6, 2017

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

@AsValeO
Copy link
Author

AsValeO commented Jul 8, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants