From fb202aa060fc5ae1b392e7618ab51fd45853d229 Mon Sep 17 00:00:00 2001 From: rabbitism Date: Thu, 4 May 2023 17:08:47 +0800 Subject: [PATCH] feat: respect DisplayMemberPath in SelectionBoxItem. --- src/Avalonia.Controls/ComboBox.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/ComboBox.cs b/src/Avalonia.Controls/ComboBox.cs index 1234b66383..dadda4e0ec 100644 --- a/src/Avalonia.Controls/ComboBox.cs +++ b/src/Avalonia.Controls/ComboBox.cs @@ -443,7 +443,22 @@ namespace Avalonia.Controls } else { - SelectionBoxItem = item; + if(ItemTemplate is null && DisplayMemberBinding is { } binding) + { + var template = new FuncDataTemplate((_, _) => + new TextBlock + { + [TextBlock.DataContextProperty] = item, + [!TextBlock.TextProperty] = binding, + }); + var text = template.Build(item); + SelectionBoxItem = text; + } + else + { + SelectionBoxItem = item; + } + } }