Yo cree uno dinamico, para poder agregar y quitar columnas/filas a gusto:
xaml
<Grid x:Name="grid"
BackgroundColor="Gray">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
</Grid>
cs
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
var cols = grid.ColumnDefinitions.Count;
var rows = grid.RowDefinitions.Count;
for (int col = 0; col < cols; col++)
{
for (int row = 0; row < rows; row++)
{
var newButton = new Button();
newButton.Clicked += OnClicked;
newButton.BackgroundColor = Color.White;
Grid.SetColumn(newButton, col);
Grid.SetRow(newButton, row);
grid.Children.Add(newButton);
}
}
}
private void OnClicked(object sender, EventArgs e)
{
var currentButton = sender as Button;
currentButton.BackgroundColor = Color.Red;
currentButton.Clicked -= OnClicked;
}
}
¿Quieres ver más aportes, preguntas y respuestas de la comunidad? Crea una cuenta o inicia sesión.