简体   繁体   English

网格仅创建一个框而不是 16x16 网格

[英]Grid only creating one box instead of a 16x16 grid

I'm setting up a grid that can be tapped to change colours (like a litebrite).我正在设置一个可以点击以更改颜色的网格(如 litebrite)。 However, it's not creating the whole grid, only one box.但是,它不是创建整个网格,而是创建一个框。

Here's an image of the current output: https://imgur.com/a/e8d1CPw这是当前 output 的图像: https://imgur.com/a/e8d1CPw

for (int row = 0; row < rows; row++)
    {
    for(int col = 0; col < cols; col++)
        {
        BoxView box = new BoxView
            {
                VerticalOptions = LayoutOptions.Start,
                HorizontalOptions = LayoutOptions.Start,
                Color = borderColor,
            };
        /*  add code create TapGestureRecognizer entry */
        var tap = new TapGestureRecognizer();
        box.GestureRecognizers.Add(tap);
        tap.Tapped += OnBoxViewTapped;
        //  Add the current box to the boxes list
        boxes.Add(box); 
        //  Add the current box to the mainGrid
        mainGrid.Children.Add(box); 
        }
    }

you need to specify row and col when adding to the Grid, otherwise every child will be on top of each other at 0,0添加到网格时需要指定行和列,否则每个孩子将在 0,0 处相互重叠

mainGrid.Children.Add(box,row,col); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM