AutoCompleteBox - Submit and performance

Editors for WPF Forum

Posted 4 years ago by Robert Wehofer - Vienna
Version: 20.1.0
Avatar

I have two questions concerning the wonderful AutoCompleteBox:

  • Is there a possibility to react on the Submit event of the AutoCompleteBox by using the MVVM pattern? I just found the OnSubmitted event.
  • Is there any advice for me how to cope with bound data containing a lot of items (let's say 5.000 items). I already recognize a little delay in time when entering letters in the textbox due to the suggestion list that needs to be refiltered all the time. For example could it be helpful to show only at maximum 30 or 50 suggestion items rather than to show all items fulfilling the current filter? And if so, how can I do that?

Thank you,

Robert

Comments (4)

Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Robert,

1) There isn't a command built-in, but you could call a command from your VM manually from within a Submitted event handler in your view.

2) If you are using the TextMemberPath property, there defnitely is a way to improve performance significantly since that feature performs relatively slowly, and that becomes apparent with thousands of items.  We're adding this information to the next maintenance release's documentation:

The ConvertToString method is used to convert each suggested item to a string for filtering and other purposes. This method uses the TextMemberPath property to create a binding that can obtain the string. While this process performs fine in scenarios with several hundred suggested items, it can become a performance bottleneck if there are a very large number of suggested items.

To maximize performance, it is recommended to create a class that inherits AutoCompleteBox and overrides the ConvertToString method. In the method implementation, cast the item to the specific data type you are using and return an appropriate string value, such as from one of the object's properties. This circumvents the use of a slow binding to obtain the value, and can add up to a significant performance gain, especially with large numbers of suggested items.


Actipro Software Support

Posted 4 years ago by Robert Wehofer - Vienna
Avatar

Thank you very much for your support.

ad 1) That's a workaround for sure but it still breaks the MVVM rules. Would it be possible to add a command built-in for the submit event in one of the future versions of the Editor package?

ad 2) Great advice! I inherited the AutoCompleteBox and wrote an overriden method for ConvertToString in order to directly access my used objects to convert them to a string value. The performance has really improved significantly. I'm happy!

Thank you very much,

Robert

Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Robert,

I'm glad to hear the performance is significantly better with that optimization.

Back on the submit command request, calling a VM's command programmatically in a view's event handler isn't really any different from binding the command to a Button in the XAML portion of the view, and it doing the same thing for you.  I don't feel that breaks MVVM rules since the view has to be able to call into the VM for various things like notifications via commands, etc.  Now that you have a custom AutoCompleteBox-based class, you can override OnSubmitted and execute a custom command on the bound VM similar to how a Button would execute its Command on a click.


Actipro Software Support

Posted 4 years ago by Robert Wehofer - Vienna
Avatar

Dear support team,

I handled the OnSubmit event in the inherited class for AutoCompleteBox. Everything works perfect. Great component!!!

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.