// Create a new tile for this row using common base public MetroTile AddTile(TileType type, TileWidth width, TileHeight height, string bgColor, string title, string onClick = "", string navUrl = "") { // Get the last tile added to this row MetroTile lastTileAdded = this.Tiles.LastOrDefault(); int nextLeftMargin = 0; // If this is the first tile in the row, margin is column margin if (lastTileAdded == null) { nextLeftMargin = this.Column.LeftMargin; } else { // Calculate left margin based on the previous tile in the row nextLeftMargin = lastTileAdded.LeftMargin + lastTileAdded.Width + Column.SpacingBetweenTiles; } // Now create the actual tile based on our calculations MetroTile newTile = new MetroTile(this.Column.Position, type, TopMargin, nextLeftMargin, width, height, bgColor, title, onClick, navUrl); // Add the new tile to the list of tiles for this row this.Tiles.Add(newTile); // Recalculate the width and height of this row this.Width = this.Width == 0 ? newTile.Width : this.Width + Column.SpacingBetweenTiles + newTile.Width; this.Height = this.Height < newTile.Height ? newTile.Height : this.Height; // Return the new tile so it can be further worked with return newTile; }