public void CreateCopypastaBlocks() { if (UnfilteredBlocks == null) { // display some error return; } // Column number int i = 0; // Row number int j = 0; // Vertical position is ALWAYS just the margin size - it was initially modified so now I'll just keep this useless line of code double verticalPosition = VerticalMarginSize; foreach (var item in CopypastaSource) { var block = new CopypastaBlock(item); block.Margin = new Thickness(HorizontalMarginSize, verticalPosition, 0, 0); block.HorizontalAlignment = HorizontalAlignment.Left; block.VerticalAlignment = VerticalAlignment.Top; var gridColumn = i % BlocksPerRow; i++; CopypastaGrid.Children.Add(block); Grid.SetRow(block, j); Grid.SetColumn(block, gridColumn); // Save the current layout for future use (during searches) UnfilteredBlocks.Add(block); if (i % BlocksPerRow == 0) { // change vertical margin every 3 pastas added - fourth added copypasta will be lower than the previous three j++; var row = new RowDefinition(); row.Height = new GridLength(VerticalMarginSize + block.MaxHeight); CopypastaGrid.RowDefinitions.Add(row); } } }
public BrowsePage() { InitializeComponent(); //? Translation if (Titles.Language == "EN") { ResetSearch.Content = Titles.ResetFilters_EN; MaterialDesignThemes.Wpf.HintAssist.SetHint(SearchTitleBox, Titles.Title_EN); MaterialDesignThemes.Wpf.HintAssist.SetHint(SearchContentBox, Titles.Content_EN); SearchFavouritesBox.Content = Titles.Favourite_EN; } else { ResetSearch.Content = Titles.ResetFilters; MaterialDesignThemes.Wpf.HintAssist.SetHint(SearchTitleBox, Titles.Title); MaterialDesignThemes.Wpf.HintAssist.SetHint(SearchContentBox, Titles.Content); SearchFavouritesBox.Content = Titles.Favourite; } //? End translation CopypastaSource = DatabaseOperations.WritePastasToList(); UnfilteredBlocks = new List <CopypastaBlock>(); // Make necessary calculations var tempBlock = new CopypastaBlock(null); BlocksPerRow = (int)(CopypastaGrid.MaxWidth / tempBlock.MaxWidth); // Create this many columns here for (int i = 0; i < BlocksPerRow; i++) { var column = new ColumnDefinition(); column.Width = new GridLength(1, GridUnitType.Star); CopypastaGrid.ColumnDefinitions.Add(column); } // 20 - let's assume it's the width of the VerticalScrollBar xD HorizontalMarginSize = Math.Floor((CopypastaGrid.MaxWidth - 20 - (BlocksPerRow * tempBlock.MaxWidth)) / 4);; VerticalMarginSize = 30; //! TotalHeight should be changed every time the grid is updated! TotalHeight = (CopypastaSource.Count / BlocksPerRow + 1) * tempBlock.MaxHeight + (CopypastaSource.Count / BlocksPerRow + 1) * VerticalMarginSize; this.CopypastaGrid.Height = TotalHeight; // Create all rows for (int i = 0; i < CopypastaSource.Count; i++) { if (i % BlocksPerRow == 0) { var row = new RowDefinition(); row.Height = new GridLength(VerticalMarginSize + tempBlock.MaxHeight); CopypastaGrid.RowDefinitions.Add(row); } } CreateCopypastaBlocks(); SearchTitleBox.TextChanged += SearchBox_TextChanged; SearchContentBox.TextChanged += SearchBox_TextChanged; SearchFavouritesBox.Checked += SearchFavouritesBox_Checked; SearchFavouritesBox.Unchecked += SearchFavouritesBox_Checked; }