diff --git a/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs b/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs index 2e63383030..a6cf363492 100644 --- a/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs +++ b/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs @@ -1387,7 +1387,7 @@ namespace Avalonia.Controls /// Walks through the items enumeration. Performance is not going to be /// perfect with the current implementation. /// - private async void RefreshView() + private void RefreshView() { // If we have a running filter, trigger a request first if (_filterInAction) @@ -1417,55 +1417,49 @@ namespace Avalonia.Controls var textFilter = TextFilter; var itemFilter = ItemFilter; var _newViewItems = new Collection(); - - bool success = false; - await Task.Run(() => + // if the mode is objectFiltering and itemFilter is null, we throw an exception + if (objectFiltering && itemFilter is null) { - foreach (object item in items) + // indicate that filtering is not ongoing anymore + _filterInAction = false; + _cancelRequested = false; + + throw new Exception( + "ItemFilter property can not be null when FilterMode has value AutoCompleteFilterMode.Custom"); + } + + foreach (object item in items) + { + // Exit the fitter when requested if cancellation is requested + if (_cancelRequested) { - // Exit the fitter when requested if cancellation is requested - if (_cancelRequested) - { - return; - } + return; + } - bool inResults = !(stringFiltering || objectFiltering); + bool inResults = !(stringFiltering || objectFiltering); - if (!inResults) + if (!inResults) + { + if (stringFiltering) { - if (stringFiltering) - { - inResults = textFilter!(text, FormatValue(item)); - } - else - { - if (itemFilter is null) - { - throw new Exception( - "ItemFilter property can not be null when FilterMode has value AutoCompleteFilterMode.Custom"); - } - inResults = itemFilter(text, item); - } + inResults = textFilter!(text, FormatValue(item)); } - - if (inResults) + else if (objectFiltering) { - _newViewItems.Add(item); + inResults = itemFilter!(text, item); } } - - // set success to true if we reached the end of the loop - success = true; - }); - // add new view items if filtering was successful - if (success && _view != null) - { - _view.Clear(); - _view.AddRange(_newViewItems); + if (inResults) + { + _newViewItems.Add(item); + } } + _view?.Clear(); + _view?.AddRange(_newViewItems); + // Clear the evaluator to discard a reference to the last item if (_valueBindingEvaluator != null) {