Esempio n. 1
0
        protected virtual DocumentPage CreatePage(int pageNumber)
        {
            // The index of header in the Grid
            int pageHeaderRowIndex = 0;
            int listViewRowIndex   = 1;
            int pageFooterRowIndex = 2;

            // Create Page Layout
            Page page = new Page();
            Grid grid = new Grid();

            grid.RowDefinitions.Add(new RowDefinition());
            grid.RowDefinitions.Add(new RowDefinition());
            grid.RowDefinitions.Add(new RowDefinition());

            grid.RowDefinitions[pageHeaderRowIndex].Height = new GridLength(headerSize.Height);
            grid.RowDefinitions[listViewRowIndex].Height   = new GridLength(1, GridUnitType.Star);
            grid.RowDefinitions[pageFooterRowIndex].Height = new GridLength(footerSize.Height);

            // Add ListView
            BindingList <object> list;
            Rect rect = new Rect(0, 0, PageSize.Width - PageMargin.Left - PageMargin.Right, pageHeight);

            if (printableListView.Group != null && printableListView.Group.GroupDescriptions != null)
            {
                FrameworkElement body = printableListView.Group.Render(printableListView.DataContext, sourceView, printableListView.ReportBody, 50, ref itemIndex, rect, out list);
                grid.Children.Add(body);
                Grid.SetRow(body, listViewRowIndex);
            }
            else
            {
                IList            sourceList = sourceView.SourceCollection.Cast <object>().ToList();
                FrameworkElement body       = UIUtility.createListView(sourceList, printableListView.ReportBody, 50, ref itemIndex, rect, out list);
                grid.Children.Add(body);
                Grid.SetRow(body, listViewRowIndex);
            }

            // Add Page Header
            ContentControl header = new ContentControl();

            header.Height          = headerSize.Height;
            header.ContentTemplate = printableListView.PageHeaderTemplate;
            grid.Children.Add(header);
            Grid.SetRow(header, pageHeaderRowIndex);

            // Add Page Footer
            ContentControl footer = new ContentControl();

            footer.Height          = footerSize.Height;
            footer.ContentTemplate = printableListView.PageFooterTemplate;
            grid.Children.Add(footer);
            Grid.SetRow(footer, pageFooterRowIndex);
            page.Content = grid;

            HeaderFooterDataContext headerFooterDataContext = new HeaderFooterDataContext(printableListView.DataContext, pageNumber + 1, list);

            header.Content = headerFooterDataContext;
            footer.Content = headerFooterDataContext;

            page.Arrange(new Rect(PageMargin.Left, PageMargin.Top, PageSize.Width - PageMargin.Left - PageMargin.Right, PageSize.Height - PageMargin.Top - PageMargin.Bottom));

            return(new DocumentPage(page));
        }
Esempio n. 2
0
        internal FrameworkElement Render(object parentDataContext, CollectionView sourceView, ViewBase view, int itemsApproximation, ref int itemIndex, Rect size, out BindingList <object> list)
        {
            // The index of the grid row of the ListView
            int    listViewRowIndex = 0;
            double pageHeight       = size.Height;

            // The layout of the group
            Grid grid = new Grid();

            grid.RowDefinitions.Add(new RowDefinition());
            grid.RowDefinitions[listViewRowIndex].Height = new GridLength(1, GridUnitType.Star);

            CollectionViewGroup group = sourceView.Groups[groupIndex] as CollectionViewGroup;

            // Add header
            if (groupPage == 0 && GroupHeader != null)
            {
                ContentControl groupHeaderControl = new ContentControl();
                groupHeaderControl.ContentTemplate = GroupHeader;
                groupHeaderControl.Height          = HeaderSize.Height;
                pageHeight -= HeaderSize.Height;
                groupHeaderControl.Content = new HeaderFooterDataContext(parentDataContext, group.Items);

                RowDefinition row = new RowDefinition();
                row.Height = new GridLength(HeaderSize.Height, GridUnitType.Pixel);
                grid.RowDefinitions.Insert(0, row);
                grid.Children.Add(groupHeaderControl);
                Grid.SetRow(groupHeaderControl, 0);
                listViewRowIndex++;
            }

            // Page header
            if (GroupPageHeader != null)
            {
                pageHeight -= this.PageHeaderSize.Height;
            }

            // Page footer
            if (GroupPageFooter != null)
            {
                pageHeight -= this.PageFooterSize.Height;
            }

            list = new BindingList <object>();
            ListView listview = UIUtility.createListView(group.Items, UIUtility.CreateDeepCopy <ViewBase>(view), itemsApproximation, ref itemIndex, new Rect(size.Left, size.Top, size.Width, pageHeight), out list);

            HeaderFooterDataContext headerFooterContent = new HeaderFooterDataContext(parentDataContext, list);

            headerFooterContent.IsFirstPage = groupPage == 0;

            // group page header
            if (GroupPageHeader != null)
            {
                ContentControl groupPageHeaderControl = new ContentControl();
                groupPageHeaderControl.ContentTemplate = GroupPageHeader;
                groupPageHeaderControl.Height          = this.PageFooterSize.Height;
                pageHeight -= this.PageHeaderSize.Height;
                groupPageHeaderControl.Content = headerFooterContent;

                RowDefinition row = new RowDefinition();
                row.Height = new GridLength(PageHeaderSize.Height, GridUnitType.Pixel);
                grid.RowDefinitions.Insert(listViewRowIndex, row);
                grid.Children.Add(groupPageHeaderControl);
                Grid.SetRow(groupPageHeaderControl, listViewRowIndex);
                listViewRowIndex++;
            }

            // group page footer
            if (GroupPageFooter != null)
            {
                ContentControl groupPageFooterControl = new ContentControl();
                groupPageFooterControl.ContentTemplate = GroupPageFooter;
                groupPageFooterControl.Height          = this.PageFooterSize.Height;
                pageHeight -= this.PageHeaderSize.Height;
                groupPageFooterControl.Content = headerFooterContent;

                RowDefinition row = new RowDefinition();
                row.Height = new GridLength(PageFooterSize.Height, GridUnitType.Pixel);
                grid.RowDefinitions.Insert(listViewRowIndex + 1, row);
                grid.Children.Add(groupPageFooterControl);
                Grid.SetRow(groupPageFooterControl, listViewRowIndex + 1);
            }

            // Group footer
            if (itemIndex >= group.ItemCount - 1)
            {
                headerFooterContent.IsLastPage = true;
                if (GroupFooter != null &&
                    listview.ActualHeight + FooterSize.Height <= pageHeight)
                {
                    groupPage = 0;
                    groupIndex++;
                    itemIndex = 0;
                    ContentControl groupFooterControl = new ContentControl();
                    groupFooterControl.ContentTemplate = GroupHeader;
                    groupFooterControl.Height          = FooterSize.Height;
                    pageHeight -= HeaderSize.Height;
                    groupFooterControl.Content = new HeaderFooterDataContext(parentDataContext, group.Items);

                    RowDefinition row = new RowDefinition();
                    row.Height = new GridLength(FooterSize.Height, GridUnitType.Pixel);
                    grid.RowDefinitions.Add(row);
                    grid.Children.Add(groupFooterControl);
                    Grid.SetRow(groupFooterControl, grid.RowDefinitions.Count - 1);
                }
                else
                {
                    list.Remove(list[list.Count - 1]);
                    itemIndex--;
                    (listview.ItemsSource as CollectionView).Refresh();
                    groupPage++;
                }
            }
            else
            {
                groupPage++;
            }

            grid.Children.Add(listview);
            Grid.SetRow(listview, listViewRowIndex);

            return(grid);
        }