【问题标题】:Grid only creating one box instead of a 16x16 grid网格仅创建一个框而不是 16x16 网格
【发布时间】:2019-10-19 05:46:00
【问题描述】:

我正在设置一个可以点击以更改颜色的网格(如 litebrite)。但是,它不是创建整个网格,而是创建一个框。

这是当前输出的图像: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); 
        }
    }

【问题讨论】:

  • 请不要发布代码或输出的图片。为了获得最佳响应和反馈,请将您的输出复制/粘贴到您的问题帖子中。

标签: c# xamarin


【解决方案1】:

添加到 Grid 时需要指定 row 和 col,否则每个子节点将在 0,0 处相互重叠

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多