diff --git a/samples/ControlCatalog/Pages/AutoCompleteBoxPage.xaml b/samples/ControlCatalog/Pages/AutoCompleteBoxPage.xaml
index a492808f1d..b682ebf51d 100644
--- a/samples/ControlCatalog/Pages/AutoCompleteBoxPage.xaml
+++ b/samples/ControlCatalog/Pages/AutoCompleteBoxPage.xaml
@@ -18,6 +18,10 @@
+
+
+
+
@@ -42,7 +46,6 @@
-
diff --git a/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs b/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs
index d0b894101f..ebf66164b7 100644
--- a/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs
+++ b/src/Avalonia.Controls/AutoCompleteBox/AutoCompleteBox.cs
@@ -1320,17 +1320,14 @@ namespace Avalonia.Controls
// Evaluate the conditions needed for completion.
// 1. Minimum prefix length
// 2. If a delay timer is in use, use it
- bool populateReady = newText.Length >= MinimumPrefixLength && MinimumPrefixLength >= 0;
- if (populateReady && MinimumPrefixLength == 0 && String.IsNullOrEmpty(newText) && String.IsNullOrEmpty(SearchText))
- {
- populateReady = false;
- }
- _userCalledPopulate = populateReady ? userInitiated : false;
+ bool minimumLengthReached = newText.Length >= MinimumPrefixLength && MinimumPrefixLength >= 0;
+
+ _userCalledPopulate = minimumLengthReached && userInitiated;
// Update the interface and values only as necessary
UpdateTextValue(newText, userInitiated);
- if (populateReady)
+ if (minimumLengthReached)
{
_ignoreTextSelectionChange = true;
diff --git a/tests/Avalonia.Controls.UnitTests/AutoCompleteBoxTests.cs b/tests/Avalonia.Controls.UnitTests/AutoCompleteBoxTests.cs
index acae583b5c..f31df71c0d 100644
--- a/tests/Avalonia.Controls.UnitTests/AutoCompleteBoxTests.cs
+++ b/tests/Avalonia.Controls.UnitTests/AutoCompleteBoxTests.cs
@@ -1,21 +1,15 @@
using System;
-using System.Collections;
using System.Collections.Generic;
-using System.ComponentModel;
using System.Linq;
using Avalonia.Controls.Primitives;
-using Avalonia.Controls.Presenters;
using Avalonia.Controls.Templates;
using Avalonia.Data;
-using Avalonia.Markup.Data;
-using Avalonia.Platform;
using Avalonia.Threading;
using Avalonia.UnitTests;
-using Moq;
using Xunit;
using System.Collections.ObjectModel;
-using System.Reactive.Linq;
using System.Reactive.Subjects;
+using Avalonia.Input;
namespace Avalonia.Controls.UnitTests
{
@@ -439,6 +433,29 @@ namespace Avalonia.Controls.UnitTests
});
}
+ [Fact]
+ public void Explicit_Dropdown_Open_Request_MinimumPrefixLength_0()
+ {
+ RunTest((control, textbox) =>
+ {
+ control.Text = "";
+ control.MinimumPrefixLength = 0;
+ Dispatcher.UIThread.RunJobs();
+
+ Assert.False(control.IsDropDownOpen);
+
+ control.RaiseEvent(new KeyEventArgs
+ {
+ RoutedEvent = InputElement.KeyDownEvent,
+ Key = Key.Down
+ });
+
+ Dispatcher.UIThread.RunJobs();
+
+ Assert.True(control.IsDropDownOpen);
+ });
+ }
+
///
/// Retrieves a defined predicate filter through a new AutoCompleteBox
/// control instance.
@@ -1072,14 +1089,14 @@ namespace Avalonia.Controls.UnitTests
private AutoCompleteBox CreateControl()
{
- var datePicker =
+ var autoCompleteBox =
new AutoCompleteBox
{
Template = CreateTemplate()
};
- datePicker.ApplyTemplate();
- return datePicker;
+ autoCompleteBox.ApplyTemplate();
+ return autoCompleteBox;
}
private TextBox GetTextBox(AutoCompleteBox control)
{