private void BuildTiles() { if (RowDefinitions.Any()) { RowDefinitions.Clear(); } BuildColumns(); Children.Clear(); var tiles = ItemsSource; if (tiles != null) { var numberOfRows = Math.Ceiling(tiles.Count / (float)MaxColumns); for (var i = 0; i < numberOfRows; i++) { RowDefinitions.Add(new RowDefinition { Height = 200f }); } for (var index = 0; index < tiles.Count; index++) { var column = index % MaxColumns; var row = (int)Math.Floor(index / (float)MaxColumns); var tile = BuildTile(tiles[index]); Children.Add(tile, column, row); } } }
public async Task BuildTiles <T>(IEnumerable <T> tiles) { // Wipe out the previous row definitions if they're there. if (RowDefinitions.Any()) { RowDefinitions.Clear(); } var enumerable = tiles as IList <T> ?? tiles.ToList(); var numberOfRows = Math.Ceiling(enumerable.Count / (float)MaxColumns); for (var i = 0; i < numberOfRows; i++) { RowDefinitions.Add(new RowDefinition { Height = TileHeight }); } for (var index = 0; index < enumerable.Count; index++) { var column = index % MaxColumns; var row = (int)Math.Floor(index / (float)MaxColumns); var tile = await BuildTile(enumerable[index]); Children.Add(tile, column, row); } }
public async Task BuildTiles(IEnumerable tiles) { // Wipe out the previous row definitions if they're there. if (RowDefinitions.Any()) { RowDefinitions.Clear(); } Children.Clear(); if (tiles == null) { return; } var enumerable = tiles as IList ?? tiles.Cast <object>().ToArray(); var numberOfRows = Math.Ceiling(enumerable.Count / (float)MaxColumns); HeightRequest = TileHeight * numberOfRows; InvalidateLayout(); for (var i = 0; i < numberOfRows; i++) { RowDefinitions.Add(new RowDefinition { Height = TileHeight }); } int ItemCount = enumerable.Count; int size = (int)numberOfRows * MaxColumns; for (var index = 0; index < size; index++) { var column = index % MaxColumns; var row = (int)Math.Floor(index / (float)MaxColumns); if (index < ItemCount) { var tile = await BuildTile(enumerable[index]); Children.Add(tile, column, row); } else { var tile = await BuildEmptyTile(); Children.Add(tile, column, row); } } }
protected override Size ArrangeOverride(Size _arrangeSize) { foreach (var child in Children.OfType<Expander>().Where(_expander => !_expander.IsExpanded)) { if (child.ExpandDirection == ExpandDirection.Down || child.ExpandDirection == ExpandDirection.Up) { var row = GetRow(child); if (!RowDefinitions.Any()) continue; RowDefinitions[row].Height = new GridLength(0, GridUnitType.Auto); } else { var column = GetColumn(child); if (!ColumnDefinitions.Any()) continue; ColumnDefinitions[column].Width = new GridLength(0, GridUnitType.Auto); } } return base.ArrangeOverride(_arrangeSize); }