protected static void AddElement(ref PrintPages pages, FrameworkElement element) { var size = pages.Last.UpdateAndMeasure(element); bool fits = pages.Last.Fits(size); if (pages.Last.HasElements && !fits) { pages.AddNewPage(); } pages.Last.AddElement(element); }
public void Populate(ref PrintPages pages) { if (pages.Last.HasElements) { pages.AddNewPage(); } }
public void Populate(ref PrintPages pages) { this.first = true; bool newPage = true; var subItemsSource = new ArrayList(); var mock = pages.Last.CreatePageMock(); //Debug.Print("Page height: {0}", pages.Last.Height / PrintLayout.DotsPerCm); //Debug.Print("Mock height: {0}", mock.BodySize.Height / PrintLayout.DotsPerCm); mock.AddPrintElement(this.caption); mock.AddPrintElement(this.tableHeader); double sumsize = 0; foreach (var itemSource in this.itemsSource) { if (newPage) { mock.AddPrintElement(this.columsHeader); newPage = false; } var element = PrintTemplate.Create(this.itemTemplate, itemSource); var size = mock.UpdateAndMeasure(element); //sumsize += size.Height; //Debug.Print("Element size height {0}", size.Height / PrintLayout.DotsPerCm); //Debug.Print("Height {0}", mock.BodySize.Height / PrintLayout.DotsPerCm); if (!mock.Fits(size)) { if (subItemsSource.Count > 0) { AddToPage(pages.Last, subItemsSource, false); } pages.AddNewPage(); mock = pages.Last.CreatePageMock(); if (subItemsSource.Count == 0) { mock.AddPrintElement(this.caption); mock.AddPrintElement(this.tableHeader); } subItemsSource = new ArrayList(); newPage = true; } subItemsSource.Add(itemSource); mock.AddElement(element); } var tableFooterSize = new Size(); if (this.tableFooter != null) { var tableFooterElement = this.tableFooter.Create(); tableFooterSize = mock.UpdateAndMeasure(tableFooterElement); } if (mock.Fits(tableFooterSize)) { AddToPage(pages.Last, subItemsSource, true); } else { if (subItemsSource.Count > 0) //<- neue Zeile um den Bug zu beheben. { /* hier beginnt der Bug*/ var last = subItemsSource[subItemsSource.Count - 1]; subItemsSource.RemoveAt(subItemsSource.Count - 1); AddToPage(pages.Last, subItemsSource, false); pages.AddNewPage(); AddToPage(pages.Last, new[] {last}, true); } } Debug.Print("Sumsize {0}", sumsize / PrintLayout.DotsPerCm); }