I have a ComboBox in my View which the user choose a number of TextBox's to create dynamically.
each TextBox has an Index i
, and I want to bind each of them to array[i]
.
I searched for a solution and I found that I need to use MultiBinding with a converter.
How can I set a MultiBinding for a TextBox in my C# Code, and not in XAML ? Thanks
Edit: I am creating a grid of textBoxes, in order to create a matrix, and I want to bind all of them to one array that will contain this matrix as a vector. my code:
myGrid.Children.Clear();
myGrid.RowDefinitions.Clear();
myGrid.ColumnDefinitions.Clear();
int row = int.Parse(comboBoxRow.SelectedValue.ToString());
int col = int.Parse(comboBoxCol.SelectedValue.ToString());
for (int i = 0; i < row; i++)
{
myGrid.RowDefinitions.Add(new RowDefinition());
}
for (int i = 0; i < col; i++)
{
myGrid.ColumnDefinitions.Add(new ColumnDefinition());
}
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
TextBox tb = new TextBox();
tb.SetValue(Grid.RowProperty, i);
tb.SetValue(Grid.ColumnProperty, j);
tb.SetBinding(TextBox.TextProperty, "matrixArray[j + col * i]")
myGrid.Children.Add(tb);
}
}
So what do I need to write instead of: "array[j + col * i]"
?
in ViewModel:
public string[] matrixArray{ get; set; }