C
C#12mo ago
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
1 Reply
Accord
Accord12mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.