Here I'm adding Receivable objects in an ItemsControl with an ItemTemplate in Lease section:

The DataTemplate for the ItemTemplate is:
DataTemplate receivableTemplate() {
var grid = new FrameworkElementFactory(typeof(Grid));
var col1 = new FrameworkElementFactory(typeof(ColumnDefinition));
var col2 = new FrameworkElementFactory(typeof(ColumnDefinition));
var col3 = new FrameworkElementFactory(typeof(ColumnDefinition));
var head = new FrameworkElementFactory(typeof(TextBlock));
var amount = new FrameworkElementFactory(typeof(TextBlock));
var button = new FrameworkElementFactory(typeof(CommandButton));
col2.SetValue(ColumnDefinition.WidthProperty, new GridLength(1, GridUnitType.Auto));
col3.SetValue(ColumnDefinition.WidthProperty, new GridLength(1, GridUnitType.Auto));
amount.SetValue(Grid.ColumnProperty, 1);
button.SetValue(Grid.ColumnProperty, 2);
head.SetBinding(TextBlock.TextProperty, new Binding(nameof(Receivable.HeadId)) { Converter = new HeadIdToHeadNameConverter() });
amount.SetBinding(TextBlock.TextProperty, new Binding(nameof(Receivable.Amount)));
grid.AppendChild(col1);
grid.AppendChild(col2);
grid.AppendChild(col3);
grid.AppendChild(head);
grid.AppendChild(amount);
grid.AppendChild(button);
return new DataTemplate() { VisualTree = grid };
}
so I've a CommandButton, button, in the third column but it doesn't appear because it needs some properties to be set. The plus button, I clicked to add those objects, is also a CommandButton and has been defined as:
addReceivable = new CommandButton() {
WidthAndHeight = 20,
Icon = Icons.Plus,
Command = viewModel.AddReceivable
};
all these three properties are normal property. I want to set these values for the button in receivableTemplate function. How to do that?