如何分割网格?我的意思是在具有RowDefinitions和ColumnDefinitions的设计器中?这是我的代码:
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) {
}
但是我得到了错误&#34;没有检测到安装的组件元素已经是另一个元素的孩子&#34;当它试图添加另一列时。我能做什么?如何分割网格?
答案 0 :(得分:0)
所以,我从错误信息中发现我尝试添加相同的项目(duh),所以我需要做的只是创建新对象:
column = new ColumnDefinition();
所以我的代码现在是这样的:
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) {
}