void OnTapGestureTapped(object sender, EventArgs args) { LifeCell lifeCell = (LifeCell)sender; lifeCell.IsAlive ^= true; lifeGrid.SetStatus(lifeCell.Col, lifeCell.Row, lifeCell.IsAlive); }
void UpdateLives() { foreach (View view in absoluteLayout.Children) { LifeCell lifeCell = view as LifeCell; lifeCell.IsAlive = lifeGrid.IsAlive(lifeCell.Col, lifeCell.Row); } }
void UpdateLayout() { // TODO: Put up Activity Indicator int count = rows * cols; System.Diagnostics.Debug.WriteLine("Count = " + count); // Remove unneeded LifeCell children while (absoluteLayout.Children.Count > count) { absoluteLayout.Children.RemoveAt(0); } // Possibly add more LifeCell children while (absoluteLayout.Children.Count < count) { LifeCell lifeCell = new LifeCell(); lifeCell.Tapped += OnTapGestureTapped; absoluteLayout.Children.Add(lifeCell); } int index = 0; for (int x = 0; x < cols; x++) { for (int y = 0; y < rows; y++) { LifeCell lifeCell = lifeCell = (LifeCell)absoluteLayout.Children[index]; lifeCell.Col = x; lifeCell.Row = y; lifeCell.IsAlive = lifeGrid.IsAlive(x, y); Rectangle rect = new Rectangle(x * cellSize + xMargin + CellSpacing / 2, y * cellSize + yMargin + CellSpacing / 2, cellSize - CellSpacing, cellSize - CellSpacing); AbsoluteLayout.SetLayoutBounds(lifeCell, rect); index++; } } }