代码之家  ›  专栏  ›  技术社区  ›  me.at.coding

清除网格单元

wpf
  •  0
  • me.at.coding  · 技术社区  · 14 年前

    非常感谢您的提示!

    2 回复  |  直到 14 年前
        1
  •  4
  •   Martin Hennings    14 年前

    找到了一个更稳定的解决方案,尽管它需要通过细胞循环:

            // these are the row and column number of the cell
            // you want to have removed...
            int getRow = 2, getCol = 5;
            for (int i = 0; i < myGrid.Children.Count; i++)
                if ((Grid.GetRow(myGrid.Children[i]) == getRow)
                    && (Grid.GetColumn(myGrid.Children[i]) == getCol))
                {
                    myGrid.Children.Remove(myGrid.Children[i]);
                    break;
                }
    
        2
  •  0
  •   Martin Hennings    14 年前

    int cellNumber = rowNumber * columnCount + columnNumber;
    

    那么 myGrid.Children[cellNumber-1]

    myGrid.Children.RemoveAt(ellNumber-1); 将从网格中删除该子节点。

    请注意,它只会从网格的子级列表中删除。如果你有任何其他的参考资料,你必须照顾他们,太。