Items Binding (ListBox, ComboBox, ItemsControl)
Introduction
Items Binding Concepts
ItemsControl Binding
public class ExampleViewModel : ViewModel
{
public ObservableCollection<DateTime> Dates
{
get;
private set;
} = new ObservableCollection<DateTime>();
}
//------------------------------------------
var viewModel = new ExampleViewModel();
var stackPanel = new StackPanel();
stackPanel.AddToRoot();
stackPanel.Anchor(Anchor.Center);
var itemsControl = new ItemsControl();
stackPanel.AddChild(itemsControl);
itemsControl.Width = 200;
itemsControl.BindingContext = viewModel;
itemsControl.SetBinding(
nameof(itemsControl.Items),
nameof(viewModel.Dates));
var addButton = new Button();
stackPanel.AddChild(addButton);
addButton.Text = "Add Date";
addButton.Click += (_, _) =>
{
viewModel.Dates.Add(DateTime.Now);
};


Last updated
Was this helpful?

