Ejemplo n.º 1
0
        /// <summary> Creates the SinglePrintedPage with the correct layout. </summary>
        private SinglePrintedPage CreateNthPage(int pageNumber)
        {
            bool shouldShowBorder = pageNumber % 2 == 0;

            Visibility showBorder = shouldShowBorder
        ? Visibility.Visible
        : Visibility.Collapsed;

            var margin = new Thickness(
                Settings.Default.Margin_Left * PixelsPerInch,
                Settings.Default.Margin_Top * PixelsPerInch,
                Settings.Default.Margin_Right * PixelsPerInch,
                Settings.Default.Margin_Bottom * PixelsPerInch
                );

            var page = new SinglePrintedPage
            {
                Header      = { Tag = _practiceNumberTitle },
                Categories  = { Visibility = showBorder },
                Footer      = { Visibility = showBorder },
                Width       = PixelsPerInch * 8.5 - margin.Left - margin.Right,
                Height      = PixelsPerInch * 11 - margin.Top - margin.Top,
                DataContext = _viewModel,
                Margin      = margin
            };

            // clear its children that are there only for mocking purposes.
            page.PrimaryContent.Children.Clear();

            return(page);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///  Creates all a collection of pages that need to be printed if the view model were to be
        ///  printed.
        /// </summary>
        public IEnumerable <PageContent> CreatePages()
        {
            int pageNumber         = 1;
            int startIndexToLayout = 0;

            var pagesToPrint = new List <SinglePrintedPage>();

            while (startIndexToLayout < _controlsToPlace.Count)
            {
                var currentPage = CreateNthPage(pageNumber);
                startIndexToLayout = LayoutAsManyControlsAsPossible(currentPage, startIndexToLayout);

                pagesToPrint.Add(currentPage);
                pageNumber++;
            }

            // we always want an even number of pages
            while (pageNumber % 2 != 1)
            {
                pagesToPrint.Add(CreateNthPage(pageNumber));
                pageNumber++;
            }

            // update the page counts to make sure that it actually works
            for (var i = 0; i < pagesToPrint.Count; i++)
            {
                SinglePrintedPage tempQualifier = pagesToPrint[i];
                tempQualifier.PageNumber         = i + 1;
                tempQualifier.TotalNumberOfPages = pagesToPrint.Count;
            }

            return(pagesToPrint.Select(ConstructPageContentFor));
        }
Ejemplo n.º 3
0
        /// <summary> Create a new PageControl for the given printed page. </summary>
        private static PageContent ConstructPageContentFor(SinglePrintedPage singlePrintedPage)
        {
            var page = new PageContent();

            page.Child = new FixedPage();
            page.Child.Children.Add(singlePrintedPage);
            return(page);
        }
Ejemplo n.º 4
0
        /// <summary> Put as many controls from the collection on the current page. </summary>
        /// <param name="currentPage"> The current page on which controls should be laid out. </param>
        /// <param name="controlIndex"> The index of the first control to add. </param>
        /// <returns> The index of the next control to lay out on the next page. </returns>
        private int LayoutAsManyControlsAsPossible(SinglePrintedPage currentPage,
                                                   int controlIndex)
        {
            bool hasMoreSpace = true;

            while (controlIndex < _controlsToPlace.Count && hasMoreSpace)
            {
                var controlToPlace = _controlsToPlace[controlIndex];

                currentPage.PrimaryContent.Children.Add(controlToPlace);
                currentPage.UpdateLayout();

                currentPage.Measure(new Size(currentPage.Width, currentPage.Height));
                currentPage.Arrange(new Rect(0, 0, currentPage.Width, currentPage.Height));

                if (!IsUserVisible(controlToPlace, currentPage.AllowedSpace))
                {
                    hasMoreSpace = false;
                    currentPage.PrimaryContent.Children.Remove(controlToPlace);
                    controlIndex--;

                    if (controlIndex > 0)
                    {
                        // titles are always attached to the next sub-section
                        var previousControl = _controlsToPlace[controlIndex];
                        if ((previousControl.Content as SubSectionEntryViewModel)?.SectionType == SubSectionType.Title)
                        {
                            currentPage.PrimaryContent.Children.Remove(previousControl);
                            controlIndex--;
                        }
                    }
                }

                controlIndex++;
            }
            return(controlIndex);
        }