diff --git a/src/Avalonia.Controls/AutoCompleteBox.cs b/src/Avalonia.Controls/AutoCompleteBox.cs index 5c95932c1f..c675139831 100644 --- a/src/Avalonia.Controls/AutoCompleteBox.cs +++ b/src/Avalonia.Controls/AutoCompleteBox.cs @@ -392,6 +392,8 @@ namespace Avalonia.Controls private AutoCompleteSelector? _itemSelector; private AutoCompleteSelector? _textSelector; + private readonly EventHandler _populateDropDownHandler; + public static readonly RoutedEvent SelectionChangedEvent = RoutedEvent.Register(nameof(SelectionChanged), RoutingStrategies.Bubble, typeof(AutoCompleteBox)); @@ -668,6 +670,7 @@ namespace Avalonia.Controls if (newValue == TimeSpan.Zero) { + _delayTimer.Tick -= _populateDropDownHandler; _delayTimer = null; } } @@ -678,7 +681,7 @@ namespace Avalonia.Controls if (_delayTimer == null) { _delayTimer = new DispatcherTimer(); - _delayTimer.Tick += PopulateDropDown; + _delayTimer.Tick += _populateDropDownHandler; } // Set the new tick interval @@ -864,6 +867,7 @@ namespace Avalonia.Controls /// public AutoCompleteBox() { + _populateDropDownHandler = PopulateDropDown; ClearView(); } @@ -1771,10 +1775,7 @@ namespace Avalonia.Controls /// The event arguments. private void PopulateDropDown(object? sender, EventArgs e) { - if (_delayTimer != null) - { - _delayTimer.Stop(); - } + _delayTimer?.Stop(); // Update the prefix/search text. SearchText = Text;