我需要动态创建带有列跨度的网格。
将最大列视为12,例如Bootstrap ...
如果有3个元素:
1-图像大小为4列。
2-图像大小为8列。
3-12列的标签大小。
+------------+-----------+
| | |
| 0,0 | 0,1 |
| | |
+------------+-----------+
| | |
| 1,0 | |
| | |
+------------------------+
var NumberOfColumns = 12.0 / layoutElements.Min(x => x.Colsize);
var NumberOfRows = Math.Ceiling(layoutElements.Sum(x => x.Colsize) / 12.0);
for (int ColNo = 0; ColNo < NumberOfColumns; ColNo++) {
ColumnDefinition gridColo = new ColumnDefinition();
cardGrid.ColumnDefinitions.Add(gridColo);
}
for (int RowNo = 0; RowNo < NumberOfRows; RowNo++) {
RowDefinition gridRow = new RowDefinition();
cardGrid.RowDefinitions.Add(gridRow);
}
Label lblTestObject3 = new Label();
lblTestObject3.Content = "Test Label .........";
Grid.SetRow(lblTestObject3, 3);
Grid.SetColumn(lblTestObject3, 3);
cardGrid.Children.Add(lblTestObject3);
Label lblTestObject4 = new Label();
lblTestObject4.Content = "Test Label------- ";
Grid.SetRow(lblTestObject4, 1);
Grid.SetColumn(lblTestObject4, 3);
cardGrid.Children.Add(lblTestObject4);
我正在使用标签控件进行测试,但是元素已被覆盖,此外,我需要合并列。