© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
1 reply
Ezekiel

❔ Populate a grid .NET MAUI

Hello guys, I want to create a grid following some logic but I can't find a solution.
I use 2 bindableProperties to know how many rows and columns I should create, like so
public static readonly BindableProperty OptionsProperty = BindableProperty.Create(
        nameof(Options), typeof(List<Option>), typeof(LikertMultiple), propertyChanged: (bindable, oldValue, newValue) =>
        {
            var control = (LikertMultiple)bindable;
            control.OptionsLabels.ItemsSource = (List<Option>)newValue;

            control.columns = new List<ColumnDefinition>();
            for (int i = 0; i < control.NumberOfColumns; i++)
            {
                ColumnDefinition col = new ColumnDefinition();
                control.columns.Add(col);
                control.myGrid.ColumnDefinitions.Add(col);
            }
        });

    public static readonly BindableProperty RowsProperty = BindableProperty.Create(
        nameof(Rows), typeof(List<LikertQuestion>), typeof(LikertMultiple), propertyChanged: (bindable, oldValue, newValue) =>
        {
            //Same for rows
            }
        });

    public List<Option> Options
    {
        get => (List<Option>)GetValue(OptionsProperty);
        set => SetValue(OptionsProperty, value);
    }

    public List<LikertQuestion> Rows
    {
        //same
    }
public static readonly BindableProperty OptionsProperty = BindableProperty.Create(
        nameof(Options), typeof(List<Option>), typeof(LikertMultiple), propertyChanged: (bindable, oldValue, newValue) =>
        {
            var control = (LikertMultiple)bindable;
            control.OptionsLabels.ItemsSource = (List<Option>)newValue;

            control.columns = new List<ColumnDefinition>();
            for (int i = 0; i < control.NumberOfColumns; i++)
            {
                ColumnDefinition col = new ColumnDefinition();
                control.columns.Add(col);
                control.myGrid.ColumnDefinitions.Add(col);
            }
        });

    public static readonly BindableProperty RowsProperty = BindableProperty.Create(
        nameof(Rows), typeof(List<LikertQuestion>), typeof(LikertMultiple), propertyChanged: (bindable, oldValue, newValue) =>
        {
            //Same for rows
            }
        });

    public List<Option> Options
    {
        get => (List<Option>)GetValue(OptionsProperty);
        set => SetValue(OptionsProperty, value);
    }

    public List<LikertQuestion> Rows
    {
        //same
    }


So this works, like it creates a grid and if i put some new elements in the grid such as
myGrid.setColumn(text, 1);
myGrid.setRow(text, 1);
myGrid.setColumn(text, 1);
myGrid.setRow(text, 1);

it works
But what I can't understand is that the columns and rows lists are null
and if i do something like
myGrid.setColumn(columns.Count -1, 1);
myGrid.setRow(rows.Count -1, 1);
myGrid.setColumn(columns.Count -1, 1);
myGrid.setRow(rows.Count -1, 1);

it won't work.

Thank you
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

.NET MAUI Grid Display?
C#CC# / help
2y ago
.net maui Help
C#CC# / help
2y ago
.net Maui Help
C#CC# / help
2y ago
✅ .NET MAUI Layout
C#CC# / help
2y ago