diff --git a/src/Avalonia.Controls/ComboBox.cs b/src/Avalonia.Controls/ComboBox.cs index dbdbf4b536..e34f9d2613 100644 --- a/src/Avalonia.Controls/ComboBox.cs +++ b/src/Avalonia.Controls/ComboBox.cs @@ -471,7 +471,7 @@ namespace Avalonia.Controls } else { - if(ItemTemplate is null && SelectionBoxItemTemplate is null && DisplayMemberBinding is { } binding) + if (item is not null && ItemTemplate is null && SelectionBoxItemTemplate is null && DisplayMemberBinding is { } binding) { var template = new FuncDataTemplate((_, _) => new TextBlock diff --git a/tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs b/tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs index 65243fa445..22cafb403b 100644 --- a/tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs +++ b/tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs @@ -517,5 +517,24 @@ namespace Avalonia.Controls.UnitTests Assert.Equal(itemTemplate2, target.SelectionBoxItemTemplate); } + + [Fact] + public void DisplayMemberBinding_Is_Not_Applied_To_SelectionBoxItem_Without_Selection() + { + var target = new ComboBox + { + DisplayMemberBinding = new Binding(), + ItemsSource = new[] { "foo", "bar" } + }; + + target.SelectedItem = null; + Assert.Null(target.SelectionBoxItem); + + target.SelectedItem = "foo"; + Assert.NotNull(target.SelectionBoxItem); + + target.SelectedItem = null; + Assert.Null(target.SelectionBoxItem); + } } }