Split grid in UWP code
How can I split the grid? I mean, how in a designer with RowDefinitions and ColumnDefinitions? Here's my code:
composite = (Windows.Storage.ApplicationDataCompositeValue)roamingSettings.Values["enabledDays"];
ColumnDefinition column = new ColumnDefinition();
column.Width = new GridLength(20, GridUnitType.Star);
grid.ColumnDefinitions.Add(column);
try {
foreach (KeyValuePair<string, object> MonthBool in composite) {
if ((bool)MonthBool.Value) {
column.Width = new GridLength(100, GridUnitType.Star);
grid.ColumnDefinitions.Add(column);
}
}
}
catch (Exception) {
}
But I get the error "No installed components found. The item is already a child of another item" when it tries to add another column. What can I do? How do I split the grid?
+3
source to share
1 answer
So I figured out from the error message that I am trying to add the same item (duh), so I just need to create a new object:
column = new ColumnDefinition();
So my code now looks like this:
composite = (Windows.Storage.ApplicationDataCompositeValue)roamingSettings.Values["enabledDays"];
ColumnDefinition column = new ColumnDefinition();
column.Width = new GridLength(20, GridUnitType.Star);
grid.ColumnDefinitions.Add(column);
try {
foreach (KeyValuePair<string, object> MonthBool in composite) {
if ((bool)MonthBool.Value) {
column = new ColumnDefinition();
column.Width = new GridLength(100, GridUnitType.Star);
grid.ColumnDefinitions.Add(column);
}
}
}
catch (Exception) {
}
0
source to share