Skip to content

add ItemsSource docs in combobox.md #646

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 1 commit 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
12 changes: 6 additions & 6 deletions docs/reference/controls/combobox.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ You will probably use these properties most often:

| Property | Description |
| -------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
| `Items` | The list items collection. |
| `ItemsSource` | Gets or sets the list items collection. (Inherited from [ItemsControl](https://docs.avaloniaui.net/docs/reference/controls/itemscontrol)) |
| `Items` | Get (read only) the list items collection. |
| `SelectedIndex` | The index (zero-based) of the selected item. |
| `SelectedItem` | The selected item itself. |
| `AutoScrollToSelectedItem` | Indicates whether to automatically scroll to newly selected items. |
Expand Down Expand Up @@ -91,7 +92,7 @@ This example binds the items in a combo box using a data template. The C# code-b
```xml
<StackPanel Margin="20">
<ComboBox x:Name="fontComboBox" SelectedIndex="0"
Width="200" MaxDropDownHeight="300">
Width="200" MaxDropDownHeight="300" x:CompileBindings="False">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation shouldn't encourage users disabling compiled bindings. It's a bad (potentially app breaking) practice.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this PR intention is to make this work running from simple copy pasting, consider adding x:DataType with expected type in the DataTemplate, x:DataType="FontFamily" I suppose.

<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" FontFamily="{Binding}" />
Expand All @@ -113,10 +114,9 @@ namespace AvaloniaControls.Views
public MainWindow()
{
InitializeComponent();
fontComboBox.Items = FontManager.Current
.GetInstalledFontFamilyNames()
.Select(x => new FontFamily(x))
.OrderBy(x=>x.Name);
fontComboBox.ItemsSource = FontManager.Current
.SystemFonts
.OrderBy(x => x.Name);
fontComboBox.SelectedIndex = 0;
}
}
Expand Down