Skip to content

Update combobox.md for IsEditable changes #633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions docs/reference/controls/combobox.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 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

Expand Down Expand Up @@ -125,6 +127,34 @@ namespace AvaloniaControls.Views

<img src={ComboBoxDataTemplateScreenshot} alt="" />

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
<ComboBox PlaceholderText="Editable"
IsEditable="true"
ItemsSource="{Binding MyComplexItems}"
Text="{Binding EditableText}"
DisplayMemberBinding="{Binding DisplayValue}"
TextSearch.TextBinding="{Binding Id, DataType=viewModels:ComplexItem}"
SelectedItem="{Binding Selected}" />
```

```csharp title='C#'
public class ComplexItem
{
public int Id { get; set; }
public string DisplayValue { get; set; }
}

public class ViewModel
{
public string EditableText { get; set; }
public ComplexItem? Selected { get; set; }
}
```

## More Information

:::info
Expand Down