In my Avalonia app, I need to create controls dynamically from a user control's code-behind so I can add them to a StackPanel inside that user control. I know the names of the viewmodel properties to which the dynamic controls' properties should be bound. A viewmodel object will be assigned as the dynamic controls' data context. What is the syntax I need to create the binding for a dynamic control for a given property by name?
For example, I create a checkbox whose IsChecked property is to be bound to my viewmodel's IsActivated property. In pure XAML, it would resemble:
<CheckBox IsChecked="{Binding IsActivated}" Content="Activated"/>
I'm looking for code-behind that looks something like:
var instanceVM = new TheViewModel { IsActviated = true };
var chkBox = new CheckBox { Content = "Activated" };
chkBox.Bind(TextBlock.TextProperty, "IsActivated");
myStackPanel.Children.Add(chkBox);
myStackPanel.DataContext = instanceVM;
How can I do this? Thanks...