Este es el tipo de tabla que estoy tratando de hacer en xaml:
Entrada del usuario:
A B C D E
Tabla generada:
tipo | UN | B | C | D | Y |
---|---|---|---|---|---|
X | 1.1 | 4.6 | 5.7 | 8.8 | 10.1 |
y | 14.5 | 9.8 | 8.1 | 4.3 | 2.4 |
Solución del problema
(Código detrás)
//clear rows & columns
DataGrid.Items.Clear();
DataGrid.Columns.Clear();
//add type Column
DataGridTextColumn typeColumn = new DataGridTextColumn();
typeColumn.Header = "Type";
typeColumn.Binding = new Binding("Type");
DataGrid.Columns.Add(typeColumn);
//Define rows
var xRow = new ExpandoObject() as IDictionary<string, object>;
var yRow = new ExpandoObject() as IDictionary<string, object>;
xRow.Add("Type", "X");
yRow.Add("Type", "Y");
//Get user input
string input = UserInput.Text;
//Add columns
for (int i = 0; i < input.Length; i++)
{
DataGridTextColumn column = new DataGridTextColumn();
column.Header = input[I];
column.Binding = new Binding(input[i].ToString());
DataGrid.Columns.Add(column);
//fill data
xRow.Add(input[i].ToString(), 1.1);
yRow.Add(input[i].ToString(), 1.1);
}
//Add rows
DataGrid.Items.Add(xRow);
DataGrid.Items.Add(yRow);
El problema con este enfoque es que el usuario no puede agregar la misma letra/columna dos veces debido al Diccionario, pero puede adaptar y cambiar el código para que se ajuste a sus necesidades.
No hay comentarios:
Publicar un comentario