【发布时间】:2016-08-17 03:14:36
【问题描述】:
我有一个网格正在覆盖图像。用户将输入以米为单位的总图像长度和宽度。他们还将输入他们想要的列和行的大小。 例如,图像长 143 米,宽 216 米,他们希望网格单元为 10 米宽 x 15 米高。 所以我需要 14 个等宽的单元格和 1 个是前 14 个宽度的 30% 的单元格。我通过循环添加列
numColumns = Convert.ToInt32(Math.Ceiling(143 / 10));
numRows = Convert.ToInt32(Math.Ceiling(216 / 15));
for(int i = 0; i < numColumns + 1; i++)
{
ColumnDefinition col = new ColumnDefinition();
if(i == 0)
{
col.Width = new GridLength(gridHeaderOffset);
}
else if(i < numColumns)
{
col.Width = new GridLength(1,GridUnitType.Auto);
}
else
{
col.Width = new GridLength(Math.Round( (143 % 10), 2), GridUnitType.Star);
}
grid.ColumnDefinitions.Add(col);
}
【问题讨论】:
标签: c# wpf grid-layout