From d34a8b79e4d613973474e507fbcb408ece63773a Mon Sep 17 00:00:00 2001 From: Julian Date: Thu, 3 Apr 2025 21:25:28 +0100 Subject: [PATCH 1/2] Update combobox.md for IsEditable changes --- docs/reference/controls/combobox.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/reference/controls/combobox.md b/docs/reference/controls/combobox.md index dde3b0716..4cf60cc5e 100644 --- a/docs/reference/controls/combobox.md +++ b/docs/reference/controls/combobox.md @@ -31,6 +31,8 @@ You will probably use these properties most often: | `MaxDropDownHeight` | The maximum height for the dropdown list. This is the actual height of the list part, not the number of items that show. | | `ItemPanel` | The container panel to place items in. By default, this is a StackPanel. See [this page](../../concepts/custom-itemspanel) to customise the ItemsPanel.| | `Styles` | The style that is applied to any child element of the ItemControl. | +| `IsEditable` | Allows the user to type any value into the `ComboBox`. Make sure to use `DisplayMemberBinding` or `TextSearch.TextBinding` if using complex item types. | +| `Text` | When `IsEditable` will be the text value of the `SelectedItem` or the text a user has entered. | ## Examples @@ -125,6 +127,28 @@ namespace AvaloniaControls.Views +When using `IsEditable` with complex types it is important to set either `DisplayMemberBinding` or `TextSearch.TextBinding`, or both. +A complex example of the editable text using `Id` to match items when typing in text, but the showing `DisplayValue` in the dropdown is found below: + +```xml + +``` + +```csharp title='C#' +public record ComplexItem(int Id, string DisplayValue); + +public class ViewModel +{ + public string EditableText { get; set; } + public ComplexItem? Selected { get; set; } +} +``` + ## More Information :::info From 140ae248649e482ccd43c468fa6ed768bb242ff0 Mon Sep 17 00:00:00 2001 From: Julian Date: Fri, 4 Apr 2025 14:34:12 +0100 Subject: [PATCH 2/2] Update combobox.md after some changes to the code --- docs/reference/controls/combobox.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/docs/reference/controls/combobox.md b/docs/reference/controls/combobox.md index 4cf60cc5e..d57f2e18f 100644 --- a/docs/reference/controls/combobox.md +++ b/docs/reference/controls/combobox.md @@ -31,8 +31,8 @@ You will probably use these properties most often: | `MaxDropDownHeight` | The maximum height for the dropdown list. This is the actual height of the list part, not the number of items that show. | | `ItemPanel` | The container panel to place items in. By default, this is a StackPanel. See [this page](../../concepts/custom-itemspanel) to customise the ItemsPanel.| | `Styles` | The style that is applied to any child element of the ItemControl. | -| `IsEditable` | Allows the user to type any value into the `ComboBox`. Make sure to use `DisplayMemberBinding` or `TextSearch.TextBinding` if using complex item types. | -| `Text` | When `IsEditable` will be the text value of the `SelectedItem` or the text a user has entered. | +| `IsEditable` | Allows the user to type any value into the `ComboBox`. Make sure to use `DisplayMemberBinding` or `TextSearch.TextBinding` if using complex item types as otherwise it will use `ToString` on the object. | +| `Text` | When `IsEditable` `Text` will be the text value of the `SelectedItem` or the text a user has entered. | ## Examples @@ -127,11 +127,13 @@ namespace AvaloniaControls.Views -When using `IsEditable` with complex types it is important to set either `DisplayMemberBinding` or `TextSearch.TextBinding`, or both. -A complex example of the editable text using `Id` to match items when typing in text, but the showing `DisplayValue` in the dropdown is found below: +When using `IsEditable` with complex types by default the `Text` will retreived from `ComplexType`.`ToString`, to change this set either `DisplayMemberBinding` or `TextSearch.TextBinding`, or both. + +The below example of an `IsEditable` `ComboBox` uses a property named `Id` to match items when typing in text. When the `ComboBox` is open the items in the dropdown will be displayed using `DisplayValue`: ```xml -