I have a ComboBox in AvaloniaUI, and I want to load the list dynamically based off the names provided by an array of another class. For example, take the following code:
<ComboBox Name="Select" SelectedIndex="0"></ComboBox>
public class MainWindow : Window
{
private Note[] notes;
public MainWindow()
{
InitializeComponent();
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
notes = Utility.GetNotes();
ComboBox comboBox = this.Find<ComboBox>("Select");
foreach (Note n in notes)
{
comboBox.Items.Add(
new ComboBoxItem()
{
Content = n.Name
}
);
}
}
}
public class Note
{
public string Name;
public string NoteText;
}
I'm not sure of the proper way to do this in AvaloniaUI since in WPF you could just directly call that comboBox.Items.Add() function. However that function doesn't seem to exist when using AvaloniaUI.