question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] Grid.Children missing Add convenience methods

See original GitHub issue

Description

Error:

error CS1501: No overload for method 'Add' takes 3 arguments

Code:

var grid = new Microsoft.Maui.Controls.Layout2.GridLayout
{
    RowSpacing = 0,
    ColumnSpacing = 0,
    RowDefinitions =
    {
        new RowDefinition(),
        new RowDefinition(),
        new RowDefinition()
    },
    ColumnDefinitions =
    {
        new ColumnDefinition(),
        new ColumnDefinition(),
        new ColumnDefinition()
    }
};

grid.Children.Add(new BoxView
{
    Color = Color.DarkSlateBlue
}, 2, 1);

I see now that you cannot do RowDefinitions/ColumnDefinitions that way anymore? And you cannot add views to Children.

grid.Add(new BoxView
            {
                Color = Color.LightSkyBlue
            });

That ^ also doesn’t allow 3 args.

Basic Information

  • Version with issue: Preview 3

Workaround

Use the Add methods off Grid instead of Grid.Children.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:8
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
breenbobcommented, Jun 24, 2022

You can workaround this for now by calling SetRow/Column explicitly:

grid.SetRow((IView)view1, 0);
grid.SetColumn((IView)view1, 0);

grid.SetRow((IView)view2, 0);
grid.SetColumn((IView)view2, 1);

grid.Children.Add(view1);
grid.Children.Add(view2);

The cast is necessary because of this: image

1reaction
jfversluiscommented, Feb 16, 2023

The API docs are wrong at this point. There were taken from Forms and not updated for .NET MAUI yet.

It seems that we have a replacement for the 3 argument overload. It’s not done on the Grid.Children anymore, but you can do it on Grid directly. So: Grid.Add(new Label(), 1, 1);.

The 5 arguments overload is provided in a PR here and we’re discussing if this is something we want to take in as it seems a bit of a confusing API.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding unique keys for array children in React.js
Each of the dynamic data rows has a unique key assigned to it but I'm still getting an error of: Each child in...
Read more >
GridLayout
A layout that places its children in a rectangular grid. ... Convenience method for sending a AccessibilityEvent#TYPE_ANNOUNCEMENT AccessibilityEvent to ...
Read more >
Angular Data Grid: Cell Renderer
Cell Renderer. Below is an example of cell renderer class: import {Component} from "@angular/core"; import {ICellRendererAngularComp} from 'ag-grid-angular' ...
Read more >
GridPane (JavaFX 8)
Convenience method for placing the specified nodes sequentially in a given column of the gridpane. void, addRow(int rowIndex, Node... children). Convenience ...
Read more >
Auto-Sizing Columns in CSS Grid: `auto-fill` vs `auto-fit`
I'll add the column into the row, and it will wrap into a new row on smaller viewports.” In the case where there...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found