0

I'm using Avalonia 11.0 and I need to accomplish the following behaviour on a custom Autocompletebox control:

  • If the input text is empty the dialog should show all the items of the collection the control is bound to.
  • Else it should show only the ones that match the "StartsWith" default filter.

My current implementation is this:

using Avalonia.Controls;

namespace Dropdown_Test.Custom_Controls;

public class AlwaysOpenAutoCompleteBox: AutoCompleteBox {
  public AlwaysOpenAutoCompleteBox() {

    TextChanged += (sender, e) => {
      if( string.IsNullOrEmpty(Text) ) {
        FilterMode = AutoCompleteFilterMode.Custom;

      } else {
        FilterMode = AutoCompleteFilterMode.StartsWith;
      }
    };
  }
}


I've tried also adding a trivial predicate that returns true after setting the FilterMode to Custom (even if by looking at the Avalonia src code returning true is the exact default behaviour implemented in the control). Also I've tried adding IsDropDownOpen = true; before and after the handling of the event.

The implementation correctly changes the filter, and in fact when the user types in some input the ItemSource collection gets correctly filtered. However the control doesn't behave as expected when the box is empty (and focused). I suspect it has something to do with the population method not being called when no characters are present in the box.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.