Esempio n. 1
0
        private void Overflow(RichTextBlockOverflow rtbo)
        {
            void Flow()
            {
                if (rtbo.HasOverflowContent && rtbo.OverflowContentTarget == null)
                {
                    var index  = IndexOf(rtbo);
                    var target = new RichTextBlockOverflow
                    {
                        MaxWidth = 800
                    };
                    target.SetBinding(RichTextBlockOverflow.PaddingProperty, _bindings.PaddingBinding);
                    rtbo.OverflowContentTarget = target;
                    Insert(index + 1, rtbo.OverflowContentTarget);
                    target.UpdateLayout();
                    Overflow(target);
                }

                else if (!rtbo.HasOverflowContent && rtbo.OverflowContentTarget != null)
                {
                    Remove(rtbo.OverflowContentTarget);
                    rtbo.OverflowContentTarget = null;
                }
            }

            rtbo.SizeChanged += (s, e) =>
            {
                Flow();
            };

            Flow();
            // rtbo.RegisterPropertyChangedCallback(RichTextBlockOverflow.HasOverflowContentProperty, HasOverflowContentPropertyChanged);
        }
Esempio n. 2
0
 public PageItem(PageItem block)
 {
     Bg       = new Border();
     Block    = new RichTextBlockOverflow();
     Bg.Child = Block;
     SetOverTarget(block);
 }
Esempio n. 3
0
        public ContinuationPageFormat(RichTextBlockOverflow textLinkContainer, FontFamily textEditorFontFamily, double textEditorFontSize, string headerText, string footerText)
        {
            InitializeComponent();

            if (!string.IsNullOrEmpty(headerText))
            {
                Header.Visibility          = Visibility.Visible;
                Header.Margin              = new Thickness(0, 0, 0, textEditorFontSize + 6);
                HeaderTextBlock.Text       = headerText;
                HeaderTextBlock.FontFamily = textEditorFontFamily;
                HeaderTextBlock.FontSize   = textEditorFontSize + 4;
            }
            else
            {
                Header.Visibility          = Visibility.Collapsed;
                HeaderTextBlock.FontFamily = textEditorFontFamily;
                HeaderTextBlock.FontSize   = textEditorFontSize + 4;
            }

            if (!string.IsNullOrEmpty(footerText))
            {
                Footer.Visibility          = Visibility.Visible;
                FooterTextBlock.Text       = footerText;
                FooterTextBlock.FontFamily = textEditorFontFamily;
                FooterTextBlock.FontSize   = textEditorFontSize;
            }
            else
            {
                Footer.Visibility          = Visibility.Collapsed;
                FooterTextBlock.FontFamily = textEditorFontFamily;
                FooterTextBlock.FontSize   = textEditorFontSize;
            }

            textLinkContainer.OverflowContentTarget = ContinuationPageLinkedContainer;
        }
        private void AddPages(Size containerSize, RichTextBlock layout)
        {
            if (_flip.Items != null)
            {
                _flip.Items.Add(new FlipViewItem {
                    Content = layout
                });
                layout.Measure(containerSize);

                if (layout.HasOverflowContent)
                {
                    var richTextBlockOverflow = new RichTextBlockOverflow();
                    layout.OverflowContentTarget = richTextBlockOverflow;
                    _flip.Items.Add(new FlipViewItem()
                    {
                        Content = richTextBlockOverflow
                    });
                    richTextBlockOverflow.Measure(containerSize);

                    while (richTextBlockOverflow.HasOverflowContent)
                    {
                        var newRichTextBlockOverflow = new RichTextBlockOverflow();
                        richTextBlockOverflow.OverflowContentTarget = newRichTextBlockOverflow;
                        richTextBlockOverflow = newRichTextBlockOverflow;
                        _flip.Items.Add(new FlipViewItem()
                        {
                            Content = richTextBlockOverflow
                        });
                        richTextBlockOverflow.Measure(containerSize);
                    }
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// This function creates and adds one print preview page to the internal cache of print preview
        /// pages stored in printPreviewPages.
        /// </summary>
        /// <param name="lastRTBOAdded">Last RichTextBlockOverflow element added in the current content</param>
        /// <param name="printPageDescription">Printer's page description</param>
        protected virtual RichTextBlockOverflow AddOnePrintPreviewPage(RichTextBlockOverflow lastRTBOAdded, PrintPageDescription printPageDescription)
        {
            // XAML element that is used to represent to "printing page"
            FrameworkElement page;

            // The link container for text overflowing in this page
            RichTextBlockOverflow textLink;

            // Check if this is the first page ( no previous RichTextBlockOverflow)
            if (lastRTBOAdded == null)
            {
                // If this is the first page add the specific scenario content
                page = firstPage;
                //Hide footer since we don't know yet if it will be displayed (this might not be the last page) - wait for layout
                StackPanel footer = (StackPanel)page.FindName("Footer");
                footer.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            }
            else
            {
                // Flow content (text) from previous pages
                page = new ContinuationPage(lastRTBOAdded);
            }

            // Set "paper" width
            page.Width  = printPageDescription.PageSize.Width;
            page.Height = printPageDescription.PageSize.Height;

            Grid printableArea = (Grid)page.FindName("PrintableArea");

            // Get the margins size
            // If the ImageableRect is smaller than the app provided margins use the ImageableRect
            double marginWidth  = Math.Max(printPageDescription.PageSize.Width - printPageDescription.ImageableRect.Width, printPageDescription.PageSize.Width * ApplicationContentMarginLeft * 2);
            double marginHeight = Math.Max(printPageDescription.PageSize.Height - printPageDescription.ImageableRect.Height, printPageDescription.PageSize.Height * ApplicationContentMarginTop * 2);

            // Set-up "printable area" on the "paper"
            printableArea.Width  = firstPage.Width - marginWidth;
            printableArea.Height = firstPage.Height - marginHeight;

            // Add the (newley created) page to the print canvas which is part of the visual tree and force it to go
            // through layout so that the linked containers correctly distribute the content inside them.
            PrintCanvas.Children.Add(page);
            PrintCanvas.InvalidateMeasure();
            PrintCanvas.UpdateLayout();

            // Find the last text container and see if the content is overflowing
            textLink = (RichTextBlockOverflow)page.FindName("ContinuationPageLinkedContainer");

            // Check if this is the last page

            /*if (!textLink.HasOverflowContent && textLink.Visibility == Windows.UI.Xaml.Visibility.Visible)
             * {
             *  StackPanel footer = (StackPanel)page.FindName("Footer");
             *  footer.Visibility = Windows.UI.Xaml.Visibility.Visible;
             * }*/

            // Add the page to the page preview collection
            printPreviewPages.Add(page);

            return(textLink);
        }
Esempio n. 6
0
        public ContinuationPage(RichTextBlockOverflow textLinkContainer)

        {
            this.InitializeComponent();

            textLinkContainer.OverflowContentTarget = ContinuationPageLinkedContainer;
        }
Esempio n. 7
0
 public PrintPage(RichTextBlockOverflow textLinkContainer)
     : this()
 {
     if (textLinkContainer == null)
     {
         throw new ArgumentNullException(nameof(textLinkContainer));
     }
     textLinkContainer.OverflowContentTarget = textOverflow;
 }
Esempio n. 8
0
        private void RichTextBlockOverflow_Loaded(object sender, RoutedEventArgs e)
        {
            RichTextBlockOverflow flow = sender as RichTextBlockOverflow;

            if (flow != null)
            {
                flow.Width = PerfectColumnWith;
            }
        }
        private void ShowContent(string selectionText)
        {
            bool hasSelection = !string.IsNullOrEmpty(selectionText);

            selectionMode = hasSelection;

            // Hide/show images depending by the selected text
            StackPanel header = (StackPanel)firstPage.FindName("Header");

            header.Visibility = hasSelection ? Windows.UI.Xaml.Visibility.Collapsed : Windows.UI.Xaml.Visibility.Visible;
            Grid pageContent = (Grid)firstPage.FindName("PrintableArea");

            pageContent.RowDefinitions[0].Height = GridLength.Auto;

            Image scenarioImage = (Image)firstPage.FindName("ScenarioImage");

            scenarioImage.Visibility = hasSelection ? Windows.UI.Xaml.Visibility.Collapsed : Windows.UI.Xaml.Visibility.Visible;

            // Expand the middle paragraph on the full page if printing only selected text
            RichTextBlockOverflow firstLink = (RichTextBlockOverflow)firstPage.FindName("FirstLinkedContainer");

            firstLink.SetValue(Grid.ColumnSpanProperty, hasSelection ? 2 : 1);

            // Clear(hide) current text and add only the selection if a selection exists
            RichTextBlock mainText = (RichTextBlock)firstPage.FindName("TextContent");

            RichTextBlock textSelection = (RichTextBlock)firstPage.FindName("TextSelection");

            // Main (default) scenario text
            mainText.Visibility            = hasSelection ? Windows.UI.Xaml.Visibility.Collapsed : Windows.UI.Xaml.Visibility.Visible;
            mainText.OverflowContentTarget = hasSelection ? null : firstLink;

            // Scenario text-blocks used for displaying selection
            textSelection.OverflowContentTarget = hasSelection ? firstLink : null;
            textSelection.Visibility            = hasSelection ? Windows.UI.Xaml.Visibility.Visible : Windows.UI.Xaml.Visibility.Collapsed;
            textSelection.Blocks.Clear();

            // Force the visual root to go through layout so that the linked containers correctly distribute the content inside them.
            PrintCanvas.InvalidateArrange();
            PrintCanvas.InvalidateMeasure();
            PrintCanvas.UpdateLayout();

            // Add the text selection if any
            if (hasSelection)
            {
                Run inlineText = new Run();
                inlineText.Text = selectionText;

                Paragraph paragraph = new Paragraph();
                paragraph.Inlines.Add(inlineText);

                textSelection.Blocks.Add(paragraph);
            }
        }
        protected override RichTextBlockOverflow AddOnePrintPreviewPage(RichTextBlockOverflow lastRTBOAdded, PrintPageDescription printPageDescription)
        {
            RichTextBlockOverflow textLink = base.AddOnePrintPreviewPage(lastRTBOAdded, printPageDescription);

            // Don't show footer in selection mode
            if (selectionMode)
            {
                FrameworkElement page   = (FrameworkElement)printPreviewPages[printPreviewPages.Count - 1];
                StackPanel       footer = (StackPanel)page.FindName("Footer");
                footer.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            }

            return(textLink);
        }
Esempio n. 11
0
        /// <summary>
        /// This function creates and adds one print preview page to the internal cache of print preview
        /// pages stored in printPreviewPages.
        /// </summary>
        /// <param name="lastRTBOAdded">Last RichTextBlockOverflow element added in the current content.</param>
        /// <param name="printPageDescription">Printer's page description</param>
        /// <returns>The link container for text overflowing in this page.</returns>
        protected virtual RichTextBlockOverflow AddOnePrintPreviewPage(RichTextBlockOverflow lastRTBOAdded, PrintPageDescription printPageDescription)
        {
            // XAML element that is used to represent to "printing page".
            FrameworkElement page = FirstPage;

            // The link container for text overflowing in this page.
            RichTextBlockOverflow textLink;

            // Check if this is the first page ( no previous RichTextBlockOverflow).
            if (lastRTBOAdded == null)
            {
                // Hide footer since we don't know yet if it will be displayed (this might not be the last page) - wait for layout.
                (page.FindName("Footer") as StackPanel).Visibility = Visibility.Collapsed;
            }

            // Set "paper" width.
            page.Width  = printPageDescription.PageSize.Width;
            page.Height = printPageDescription.PageSize.Height;

            var printableArea = page.FindName("PrintableArea") as Grid;

            // Get the margins size.
            // If the ImageableRect is smaller than the app provided margins use the ImageableRect.
            double marginWidth  = 0;
            double marginHeight = 0;

            // Set-up "printable area" on the "paper".
            printableArea.Width  = FirstPage.Width - marginWidth;
            printableArea.Height = FirstPage.Height - marginHeight;

            // Add the (newley created) page to the print canvas which is part of the visual tree and force it to go
            // through layout so that the linked containers correctly distribute the content inside them.
            PrintCanvas.Children.Add(page);
            PrintCanvas.InvalidateMeasure();
            PrintCanvas.UpdateLayout();

            // Find the last text container and see if the content is overflowing.
            textLink = page.FindName("ContinuationPageLinkedContainer") as RichTextBlockOverflow;

            // Check if this is the last page.
            if (!textLink.HasOverflowContent && textLink.Visibility == Visibility.Visible)
            {
                (page.FindName("Footer") as StackPanel).Visibility = Visibility.Visible;
            }

            // Add the page to the page preview collection.
            PrintPreviewPages.Add(page);

            return(textLink);
        }
Esempio n. 12
0
        private void checkOverflow(object sender, RoutedEventArgs e)
        {
            RichTextBlockOverflow textBlock = (RichTextBlockOverflow)sender;

            if (textBlock.HasOverflowContent)
            {
                RichTextBlockOverflow overflow = new RichTextBlockOverflow();
                overflow.Margin  = new Thickness(50);
                overflow.Loaded -= loadedEventHandler;
                overflow.Loaded += loadedEventHandler;
                textBlock.OverflowContentTarget = overflow;
                Overflows.Add(overflow);
                flipView.Items.Add(overflow);
            }
        }
Esempio n. 13
0
        /// <summary>
        /// This function creates and adds one print preview page to the internal cache of print preview
        /// pages stored in printPreviewPages.
        /// </summary>
        /// <param name="lastRTBOAdded">Last RichTextBlockOverflow element added in the current content</param>
        /// <param name="printPageDescription">Printer's page description</param>
        protected virtual RichTextBlockOverflow AddOnePrintPreviewPage(RichTextBlockOverflow lastRTBOAdded, PrintPageDescription printPageDescription)
        {
            // XAML element that is used to represent to "printing page"
            FrameworkElement page;


            RichTextBlockOverflow textLink;


            page = firstPage;


            // Set "paper" width
            page.Width  = printPageDescription.PageSize.Width;
            page.Height = printPageDescription.PageSize.Height;

            Grid printableArea = (Grid)page.FindName("printableArea");

            // Get the margins size
            // If the ImageableRect is smaller than the app provided margins use the ImageableRect
            double marginWidth  = Math.Max(printPageDescription.PageSize.Width - printPageDescription.ImageableRect.Width, printPageDescription.PageSize.Width * ApplicationContentMarginLeft * 2);
            double marginHeight = Math.Max(printPageDescription.PageSize.Height - printPageDescription.ImageableRect.Height, printPageDescription.PageSize.Height * ApplicationContentMarginTop * 2);

            // Set-up "printable area" on the "paper"
            printableArea.Width  = firstPage.Width - marginWidth;
            printableArea.Height = firstPage.Height - marginHeight;

            // Add the (newley created) page to the printing root which is part of the visual tree and force it to go
            // through layout so that the linked containers correctly distribute the content inside them.
            PrintingRoot.Children.Add(page);
            PrintingRoot.InvalidateMeasure();
            PrintingRoot.UpdateLayout();

            // Find the last text container and see if the content is overflowing
            textLink = (RichTextBlockOverflow)page.FindName("continuationPageLinkedContainer");

            // Check if this is the last page
            if (!textLink.HasOverflowContent && textLink.Visibility == Windows.UI.Xaml.Visibility.Visible)
            {
                //StackPanel footer = (StackPanel)page.FindName("footer");
                //footer.Visibility = Windows.UI.Xaml.Visibility.Visible;
            }

            // Add the page to the page preview collection
            printPreviewPages.Add(page);

            return(textLink);
        }
Esempio n. 14
0
        protected virtual RichTextBlockOverflow RenderOverflow(FrameworkElement target)
        {
            var tmp = new RichTextBlockOverflow();

            if (target is RichTextBlock richBlock)
            {
                richBlock.OverflowContentTarget = tmp;
            }
            else if (target is RichTextBlockOverflow of)
            {
                of.OverflowContentTarget = tmp;
            }

            tmp.Padding = Padding;
            return(tmp);
        }
Esempio n. 15
0
        private RichTextBlockOverflow AddOnePrintPreviewPage(RichTextBlockOverflow lastRTBOAdded, PrintPageDescription printPageDescription)
        {
            FrameworkElement      page;
            RichTextBlockOverflow link;

            if (lastRTBOAdded == null)
            {
                page = page1;
                StackPanel footer = (StackPanel)page.FindName("footer");
                footer.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            }
            else
            {
                page = new ContinuationPage(lastRTBOAdded);
            }

            page.Width  = printPageDescription.PageSize.Width;
            page.Height = printPageDescription.PageSize.Height;

            Grid printableArea = (Grid)page.FindName("printableArea");

            double marginWidth  = Math.Max(printPageDescription.PageSize.Width - printPageDescription.ImageableRect.Width, printPageDescription.PageSize.Width * left * 2);
            double marginHeight = Math.Max(printPageDescription.PageSize.Height - printPageDescription.ImageableRect.Height, printPageDescription.PageSize.Height * top * 2);

            printableArea.Width  = page1.Width - marginWidth;
            printableArea.Height = page1.Height - marginHeight;

            PrintContainer.Children.Add(page);
            PrintContainer.InvalidateMeasure();
            PrintContainer.UpdateLayout();

            // Find the last text container and see if the content is overflowing
            link = (RichTextBlockOverflow)page.FindName("continuationPageLinkedContainer");

            // Check if this is the last page
            if (!link.HasOverflowContent && link.Visibility == Windows.UI.Xaml.Visibility.Visible)
            {
                StackPanel footer = (StackPanel)page.FindName("footer");
                footer.Visibility = Windows.UI.Xaml.Visibility.Visible;
            }

            // Add the page to the page preview collection
            pages.Add(page);

            return(link);
        }
        private Task Process(Size containerSize)
        {
            if (_flip.Items != null && _flip.Items.Count == 0)
            {
                if (_lines != null)
                {
                    var layout = CreateLayout();
                    AddParagraph(layout);
                    AddLines(layout);
                    AddPages(containerSize, layout);

                    _lines = null;
                }
            }
            else
            {
                foreach (var obj in _flip.Items.AsNotNull())
                {
                    (obj as FrameworkElement).Measure(containerSize);
                }

                while (((_flip.Items[_flip.Items.Count - 1] as FlipViewItem).Content as RichTextBlockOverflow).HasOverflowContent)
                {
                    var richTextBlockOverflow = (_flip.Items[_flip.Items.Count - 1] as FlipViewItem).Content as RichTextBlockOverflow;

                    var newRichTextBlockOverflow = new RichTextBlockOverflow();
                    richTextBlockOverflow.OverflowContentTarget = newRichTextBlockOverflow;
                    richTextBlockOverflow = newRichTextBlockOverflow;
                    _flip.Items.Add(new FlipViewItem()
                    {
                        Content = richTextBlockOverflow
                    });

                    richTextBlockOverflow.Measure(containerSize);
                }

                // Удаление избыточных элементов RichTextBlockOverflow
                while (!((_flip.Items[_flip.Items.Count - 2] as FlipViewItem).Content as RichTextBlockOverflow).HasOverflowContent)
                {
                    _flip.Items.RemoveAt(_flip.Items.Count - 1);
                }
            }

            return(Task.FromResult(true));
        }
Esempio n. 17
0
        public void SetContent(ReaderPage readerPage)
        {
            var textBlock = new RichTextBlockOverflow();

            if (readerPage.ContentControl is RichTextBlock rtb)
            {
                rtb.OverflowContentTarget = textBlock;
            }
            else if (readerPage.ContentControl is RichTextBlockOverflow of)
            {
                of.OverflowContentTarget = textBlock;
            }

            textBlock.Margin = Padding;

            this.Content   = textBlock;
            ContentControl = textBlock;
        }
Esempio n. 18
0
        /// <summary>
        /// Creates a print preview page and adds it to the internal list.
        /// </summary>
        private RichTextBlockOverflow AddOnePrintPreviewPage(RichTextBlockOverflow lastOverflowAdded, PrintPageDescription printPageDescription)
        {
            PrintPage printPage;

            // Check if this is the first page.
            if (lastOverflowAdded == null)
            {
                printPage = _firstPrintPage;
            }
            else
            {
                // Flow content from previous pages.
                printPage = new PrintPage(lastOverflowAdded);

                // Remove the duplicate OverflowContentTarget.
                printPage.TextContent.OverflowContentTarget = null;
            }

            // Set page size.
            ApplyPrintPageDescription(printPageDescription, printPage);

            // Add title.
            var titleTextBlock = (TextBlock)printPage.FindName("title");

            if (titleTextBlock != null)
            {
                titleTextBlock.Text = Title;
            }

            // Add page number
            _pageNumber += 1;
            var pageNumberTextBlock = (TextBlock)printPage.FindName("pageNumber");

            if (pageNumberTextBlock != null)
            {
                pageNumberTextBlock.Text = string.Format("- {0} -", _pageNumber);
            }

            // Add the page to the page preview collection
            _printPreviewPages.Add(printPage);

            // The link container for text overflowing in this page
            return(printPage.TextOverflow);
        }
Esempio n. 19
0
        protected virtual RichTextBlockOverflow AddOnePrintPreviewPage(RichTextBlockOverflow lastRTBOAdded, PrintPageDescription printPageDescription)
        {
            FrameworkElement      page;
            RichTextBlockOverflow textLink;

            if (lastRTBOAdded == null)
            {
                page = firstPage;
                StackPanel footer = (StackPanel)page.FindName("Footer");
                footer.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            }
            else
            {
                page = new ContinuationPage(lastRTBOAdded);
            }

            page.Width  = printPageDescription.PageSize.Width;
            page.Height = printPageDescription.PageSize.Height;

            Grid printableArea = (Grid)page.FindName("PrintableArea");

            double marginWidth  = Math.Max(printPageDescription.PageSize.Width - printPageDescription.ImageableRect.Width, printPageDescription.PageSize.Width * ApplicationContentMarginLeft * 2);
            double marginHeight = Math.Max(printPageDescription.PageSize.Height - printPageDescription.ImageableRect.Height, printPageDescription.PageSize.Height * ApplicationContentMarginTop * 2);

            printableArea.Width  = firstPage.Width - marginWidth;
            printableArea.Height = firstPage.Height - marginHeight;

            PrintCanvas.Children.Add(page);
            PrintCanvas.InvalidateMeasure();
            PrintCanvas.UpdateLayout();

            textLink = (RichTextBlockOverflow)page.FindName("ContinuationPageLinkedContainer");

            if (!textLink.HasOverflowContent && textLink.Visibility == Windows.UI.Xaml.Visibility.Visible)
            {
                StackPanel footer = (StackPanel)page.FindName("Footer");
                footer.Visibility = Windows.UI.Xaml.Visibility.Visible;
            }

            printPreviewPages.Add(page);

            return(textLink);
        }
        protected virtual void AddPrintPreviewPages(PrintPageDescription printPageDescription)
        {
            Canvas page;
            Grid   content;

            BuildBasicLayout(printPageDescription, out page, out content);

            RichTextBlockOverflow rtbo = new RichTextBlockOverflow();

            RichTextBlock rtbl = new RichTextBlock();

            rtbl.SetValue(Grid.RowProperty, 2);
            rtbl = CreateReservationBoardingPass(rtbl);
            int a = rtbl.Blocks.Count();

            rtbl.Foreground = new SolidColorBrush(Colors.Black);
            content.Children.Add(rtbl);

            page.Children.Add(content);
            _printPreviewPages.Add(page);

            if (this._type == PrintJobType.MultiPage)
            {
                BuildBasicLayout(printPageDescription, out page, out content);

                rtbl = new RichTextBlock();
                rtbl.SetValue(Grid.RowProperty, 2);
                rtbl            = CreateReservationInvoice(rtbl);
                rtbl.Foreground = new SolidColorBrush(Colors.Black);
                content.Children.Add(rtbl);

                page.Children.Add(content);
                _printPreviewPages.Add(page);
            }

            // Add the newley created page to the printing root which is part of the visual tree and force it to go
            // through layout so that the linked containers correctly distribute the content inside them.
            PrintingRoot.InvalidateMeasure();
            PrintingRoot.UpdateLayout();
        }
Esempio n. 21
0
        void OnRichTextBlockSizeChanged(object sender, SizeChangedEventArgs args)
        {
            RichTextBlock richTextBlock = sender as RichTextBlock;

            if (richTextBlock.ActualHeight == 0)
            {
                return;
            }

            // Get rid of all previous RichTextBlockOverflow objects
            while (stackPanel.Children.Count > 1)
            {
                stackPanel.Children.RemoveAt(1);
            }

            if (!richTextBlock.HasOverflowContent)
            {
                return;
            }

            // Create first RichTextBlockOverflow
            RichTextBlockOverflow richTextBlockOverflow = new RichTextBlockOverflow();

            richTextBlock.OverflowContentTarget = richTextBlockOverflow;
            stackPanel.Children.Add(richTextBlockOverflow);

            // Measure it
            richTextBlockOverflow.Measure(new Size(richTextBlockOverflow.Width, this.ActualHeight));

            // If it has overflow content, repeat the process
            while (richTextBlockOverflow.HasOverflowContent)
            {
                RichTextBlockOverflow newRichTextBlockOverflow = new RichTextBlockOverflow();
                richTextBlockOverflow.OverflowContentTarget = newRichTextBlockOverflow;
                richTextBlockOverflow = newRichTextBlockOverflow;
                stackPanel.Children.Add(richTextBlockOverflow);
                richTextBlockOverflow.Measure(new Size(richTextBlockOverflow.Width, this.ActualHeight));
            }
        }
Esempio n. 22
0
        //This method does all of the heavy lifting for us, calculating the size of the page,
        //setting margins, and saving them to the pages List<>.
        private RichTextBlockOverflow AddOnePrintPreviewPage(RichTextBlockOverflow lastRTBOAdded, PrintPageDescription printPageDescription)
        {
            //This method does all of the heavy lifting for us, calculating the size of the
            //page, setting margins, and saving them to the pages List<>.
            FrameworkElement      page;
            RichTextBlockOverflow link;

            if (lastRTBOAdded == null)
            {
                page = page1;
            }
            else
            {
                page = new ContinuesPage(lastRTBOAdded);
            }

            page.Width  = printPageDescription.PageSize.Width;
            page.Height = printPageDescription.PageSize.Height;

            Grid printableArea = (Grid)page.FindName("printableArea");

            double marginWidth  = Math.Max(printPageDescription.PageSize.Width - printPageDescription.ImageableRect.Width, printPageDescription.PageSize.Width * left * 2);
            double marginHeight = Math.Max(printPageDescription.PageSize.Height - printPageDescription.ImageableRect.Height, printPageDescription.PageSize.Height * top * 2);

            printableArea.Width  = page1.Width - marginWidth;
            printableArea.Height = page1.Height - marginHeight;

            PrintContainer.Children.Add(page);
            PrintContainer.InvalidateMeasure();
            PrintContainer.UpdateLayout();

            // Find the last text container and see if the content is overflowing
            link = (RichTextBlockOverflow)page.FindName("continuationPageLinkedContainer");

            // Add the page to the page preview collection
            pages.Add(page);

            return(link);
        }
Esempio n. 23
0
        private void GenerateReceiptPages(PrintPageDescription printPageDescription, RichTextBlockOverflow previousOverflowContainer = null)
        {
            FrameworkElement page;

            if (previousOverflowContainer == null)
            {
                page = _firstPage;
            }
            else
            {
                page = new ReceiptContinuationPreviewPage(previousOverflowContainer);
            }

            PreparePrintPage(printPageDescription, page, page);

            var overflowContainer = (RichTextBlockOverflow)page.FindName("continuationPageLinkedContainer");

            if (overflowContainer.HasOverflowContent)
            {
                GenerateReceiptPages(printPageDescription, overflowContainer);
            }
        }
        protected override void OnApplyTemplate()
        {
            Label         = GetTemplateChild(nameof(Label)) as RichTextBlock;
            OverflowArea  = GetTemplateChild(nameof(OverflowArea)) as RichTextBlockOverflow;
            TitleLabel    = GetTemplateChild(nameof(TitleLabel)) as Run;
            SubtitleLabel = GetTemplateChild(nameof(SubtitleLabel)) as Run;
            ContentLabel  = GetTemplateChild(nameof(ContentLabel)) as Run;
            Texture       = GetTemplateChild(nameof(Texture)) as Image;
            Button        = GetTemplateChild(nameof(Button)) as Button;
            Run1          = GetTemplateChild(nameof(Run1)) as Run;
            Run2          = GetTemplateChild(nameof(Run2)) as Run;
            Run3          = GetTemplateChild(nameof(Run3)) as Run;

            Label.OverflowContentTarget = OverflowArea;
            Button.Click += Button_Click;

            _templateApplied = true;

            if (_message != null)
            {
                UpdateMessage(_message);
            }
        }
Esempio n. 25
0
        protected override RichTextBlockOverflow AddOnePrintPreviewPage(RichTextBlockOverflow lastRTBOAdded, PrintPageDescription printPageDescription)
        {
            // Check if we need to hide/show text & images for this scenario
            // Since all is rulled by the first page (page flow), here is where we must start
            if (lastRTBOAdded == null)
            {
                // Get a refference to page objects
                Grid                  pageContent      = (Grid)firstPage.FindName("printableArea");
                Image                 scenarioImage    = (Image)firstPage.FindName("scenarioImage");
                RichTextBlock         mainText         = (RichTextBlock)firstPage.FindName("textContent");
                RichTextBlockOverflow firstLink        = (RichTextBlockOverflow)firstPage.FindName("firstLinkedContainer");
                RichTextBlockOverflow continuationLink = (RichTextBlockOverflow)firstPage.FindName("continuationPageLinkedContainer");

                // Hide(collapse) and move elements in different grid cells depending by the viewable content(only text, only pictures)

                scenarioImage.Visibility = ShowImage ? Windows.UI.Xaml.Visibility.Visible : Windows.UI.Xaml.Visibility.Collapsed;
                firstLink.SetValue(Grid.ColumnSpanProperty, ShowImage ? 1 : 2);

                scenarioImage.SetValue(Grid.RowProperty, ShowText ? 2 : 1);
                scenarioImage.SetValue(Grid.ColumnProperty, ShowText ? 1 : 0);

                pageContent.ColumnDefinitions[0].Width = new GridLength(ShowText ? 6 : 4, GridUnitType.Star);
                pageContent.ColumnDefinitions[1].Width = new GridLength(ShowText ? 4 : 6, GridUnitType.Star);

                // Break the text flow if the app is not printing text in order not to spawn pages with blank content
                mainText.Visibility         = ShowText ? Windows.UI.Xaml.Visibility.Visible : Windows.UI.Xaml.Visibility.Collapsed;
                continuationLink.Visibility = ShowText ? Windows.UI.Xaml.Visibility.Visible : Windows.UI.Xaml.Visibility.Collapsed;

                // Hide header if printing only images
                StackPanel header = (StackPanel)firstPage.FindName("header");
                header.Visibility = ShowText ? Windows.UI.Xaml.Visibility.Visible : Windows.UI.Xaml.Visibility.Collapsed;
            }

            //Continue with the rest of the base printing layout processing (paper size, printable page size)
            return(base.AddOnePrintPreviewPage(lastRTBOAdded, printPageDescription));
        }
Esempio n. 26
0
 public PageItem(Border bg, RichTextBlockOverflow block)
 {
     Bg    = bg;
     Block = block;
 }
        /// <summary>
        /// “导出”的关键方法,用于添加打印选项和设置打印页面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PrintDocument_Paginate(object sender, PaginateEventArgs e)
        {
            PrintTaskOptions     printingOptions      = e.PrintTaskOptions;
            PrintPageDescription printPageDescription = printingOptions.GetPageDescription(0);

            RememberInlineUIElementsLayout(htmlBlock);

            //创建新打印页面
            page = new PageToPrint
            {
                Width             = printPageDescription.PageSize.Width,
                Height            = printPageDescription.PageSize.Height,
                VerticalAlignment = VerticalAlignment.Top
            };
            printPanel.Children.Add(page);
            printPanel.InvalidateMeasure();
            printPanel.UpdateLayout();

            //设置新页面
            pagesToPrint = new List <UIElement>();

            //记录RichTextBlock中每个控件的大小
            RememberInlineUIElementsLayout(htmlBlock);

            //将控件迁移到打印页面
            newsPanel.Width   = newsPanel.ActualWidth;
            newsPanel.Height  = printPageDescription.PageSize.Height;
            oldCanvasSize     = newsCanvas.ActualHeight;
            headerPanel.Width = headerPanel.ActualWidth;
            htmlBlock.Width   = htmlBlock.ActualWidth;
            htmlBlock.Height  = printPageDescription.PageSize.Height - headerPanel.ActualHeight;
            grid = new Grid()
            {
                Width             = newsPanel.Width,
                Height            = newsPanel.Height,
                VerticalAlignment = VerticalAlignment.Top
            };
            contentGrid.Children.Remove(newsPanel);
            grid.Children.Add(newsPanel);
            page.PrintableContentViewBox.Child = grid;
            UpdateInlineUIElementsLayout(htmlBlock, new Size(htmlBlock.Width, htmlBlock.Height));
            //更新布局
            page.InvalidateMeasure();
            page.UpdateLayout();

            //将页面添加到页面列表
            pagesToPrint.Add(page);

            bool hasOverflowContent = false;
            RichTextBlockOverflow richTextBlockOverflow = null;

            if (htmlBlock.HasOverflowContent)
            {
                hasOverflowContent    = true;
                richTextBlockOverflow = new RichTextBlockOverflow
                {
                    Height            = grid.ActualHeight,
                    Width             = grid.Width,
                    VerticalAlignment = VerticalAlignment.Top,
                };
                htmlBlock.OverflowContentTarget = richTextBlockOverflow;
            }


            while (hasOverflowContent)
            {
                ContinueonPageToPrint continueonPageToPrint = new ContinueonPageToPrint()
                {
                    Width             = printPageDescription.PageSize.Width,
                    Height            = printPageDescription.PageSize.Height,
                    VerticalAlignment = VerticalAlignment.Top
                };
                printPanel.Children.Add(continueonPageToPrint);
                printPanel.InvalidateMeasure();
                printPanel.UpdateLayout();

                Grid overFlowGrid = new Grid()
                {
                    Width  = grid.Width,
                    Height = grid.Height
                };
                StackPanel stackPanel = new StackPanel()
                {
                    Height = newsPanel.Height,
                    Width  = newsPanel.Width
                };
                stackPanel.Children.Add(richTextBlockOverflow);
                continueonPageToPrint.PrintableContentViewBox.Child = stackPanel;
                continueonPageToPrint.InvalidateMeasure();
                continueonPageToPrint.UpdateLayout();
                pagesToPrint.Add(continueonPageToPrint);

                if (richTextBlockOverflow.HasOverflowContent)
                {
                    hasOverflowContent = true;
                    var oldRichTextBlockOverflow = richTextBlockOverflow;
                    richTextBlockOverflow = new RichTextBlockOverflow
                    {
                        Height            = grid.ActualHeight,
                        Width             = htmlBlock.Width,
                        VerticalAlignment = VerticalAlignment.Top,
                    };
                    oldRichTextBlockOverflow.OverflowContentTarget = richTextBlockOverflow;
                }
                else
                {
                    hasOverflowContent = false;
                }
            }
            printDocument.SetPreviewPageCount(pagesToPrint.Count, PreviewPageCountType.Final);
        }
Esempio n. 28
0
        private void CreateReceiptPages(PrintPageDescription printPageDescription, Reservation reservation, RichTextBlockOverflow previousOverflowElement)
        {
            FrameworkElement page;

            if (previousOverflowElement == null)
            {
                page = new ReceiptPreviewPage();
            }
            else
            {
                page = new ReceiptContinuationPreviewPage(previousOverflowElement);
            }

            PreparePrintPage(printPageDescription, reservation, page, page);

            // Find the last text container and see if the content is overflowing
            var overflowContainer = (RichTextBlockOverflow)page.FindName("continuationPageLinkedContainer");

            while (overflowContainer.HasOverflowContent)
            {
                CreateReceiptPages(printPageDescription, reservation, overflowContainer);
            }
        }
Esempio n. 29
0
        /// <summary>
        /// This function creates and adds one print preview page to the internal cache of print preview
        /// pages stored in _printPreviewPages.
        /// </summary>
        /// <param name="lastRTBOAdded">Last RichTextBlockOverflow element added in the current content</param>
        /// <param name="printPageDescription">Printer's page description</param>
        private static RichTextBlockOverflow AddOnePrintPreviewPage(RichTextBlockOverflow lastRTBOAdded, PrintPageDescription printPageDescription, int count)
        {
            // XAML element that is used to represent to "printing page"
            FrameworkElement page;

            // The link container for text overflowing in this page
            RichTextBlockOverflow textLink;

            // Check if this is the first page ( no previous RichTextBlockOverflow)
            if (lastRTBOAdded == null)
            {
                // If this is the first page add the specific scenario content
                page = _firstPage[count];

                // Hide headr and footer if not provided
                StackPanel header = (StackPanel)page.FindName("Header");
                if (!string.IsNullOrEmpty(_headerText))
                {
                    header.Visibility = Visibility.Visible;
                    TextBlock headerTextBlock = (TextBlock)page.FindName("HeaderTextBlock");
                    headerTextBlock.Text = _headerText;
                }
                else
                {
                    header.Visibility = Visibility.Collapsed;
                }

                StackPanel footer = (StackPanel)page.FindName("Footer");
                if (!string.IsNullOrEmpty(_footerText))
                {
                    footer.Visibility = Visibility.Visible;
                    TextBlock footerTextBlock = (TextBlock)page.FindName("FooterTextBlock");
                    footerTextBlock.Text = _footerText;
                }
                else
                {
                    footer.Visibility = Visibility.Collapsed;
                }
            }
            else
            {
                // Flow content (text) from previous pages
                page = new ContinuationPageFormat(lastRTBOAdded,
                                                  new FontFamily(EditorSettingsService.EditorFontFamily),
                                                  EditorSettingsService.EditorFontSize,
                                                  _headerText,
                                                  _footerText);
            }

            // Set "paper" width
            page.Width  = printPageDescription.PageSize.Width;
            page.Height = printPageDescription.PageSize.Height;

            Grid printableArea = (Grid)page.FindName("PrintableArea");

            // Get the margins size
            // If the ImageableRect is smaller than the app provided margins use the ImageableRect
            double marginWidth  = Math.Max(printPageDescription.PageSize.Width - printPageDescription.ImageableRect.Width, printPageDescription.PageSize.Width * _applicationContentMarginLeft * 2);
            double marginHeight = Math.Max(printPageDescription.PageSize.Height - printPageDescription.ImageableRect.Height, printPageDescription.PageSize.Height * _applicationContentMarginTop * 2);

            // Set-up "printable area" on the "paper"
            printableArea.Width  = _firstPage[count].Width - marginWidth;
            printableArea.Height = _firstPage[count].Height - marginHeight;

            // Add the (newley created) page to the print canvas which is part of the visual tree and force it to go
            // through layout so that the linked containers correctly distribute the content inside them.
            PrintCanvas.Children.Add(page);
            PrintCanvas.InvalidateMeasure();
            PrintCanvas.UpdateLayout();

            // Find the last text container and see if the content is overflowing
            textLink = (RichTextBlockOverflow)page.FindName("ContinuationPageLinkedContainer");

            // Check if this is the last page
            if (!textLink.HasOverflowContent && textLink.Visibility == Visibility.Visible)
            {
                PrintCanvas.UpdateLayout();
            }

            // Add the page to the page preview collection
            _printPreviewPages.Add(page);

            return(textLink);
        }
Esempio n. 30
0
        protected virtual RichTextBlockOverflow AddOnePrintPreviewPage(RichTextBlockOverflow lastRTBOAdded, PrintPageDescription printPageDescription)
        {
            // Create a cavase which represents the page
            Canvas page = new Canvas();

            page.Width  = printPageDescription.PageSize.Width;
            page.Height = printPageDescription.PageSize.Height;


            // Create a grid which contains the actual content to be printed
            Grid content = new Grid();

            // Get the margins size
            // If the ImageableRect is smaller than the app provided margins use the ImageableRect
            double marginWidth = Math.Max(printPageDescription.PageSize.Width - printPageDescription.ImageableRect.Width,
                                          printPageDescription.PageSize.Width * ApplicationContentMarginLeft * 2);

            double marginHeight = Math.Max(printPageDescription.PageSize.Height - printPageDescription.ImageableRect.Height,
                                           printPageDescription.PageSize.Height * ApplicationContentMarginTop * 2);

            // Set content size based on the given margins
            content.Width  = printPageDescription.PageSize.Width - marginWidth;
            content.Height = printPageDescription.PageSize.Height - marginHeight;

            // Set content margins
            content.SetValue(Canvas.LeftProperty, marginWidth / 2);
            content.SetValue(Canvas.TopProperty, marginHeight / 2);

            // Add the RowDefinitions to the Grid which is a content to be printed
            RowDefinition rowDef = new RowDefinition();

            rowDef.Height = new GridLength(0.7, GridUnitType.Star);
            content.RowDefinitions.Add(rowDef);
            rowDef        = new RowDefinition();
            rowDef.Height = new GridLength(0.8, GridUnitType.Star);
            content.RowDefinitions.Add(rowDef);
            rowDef        = new RowDefinition();
            rowDef.Height = new GridLength(2.5, GridUnitType.Star);
            content.RowDefinitions.Add(rowDef);
            rowDef        = new RowDefinition();
            rowDef.Height = new GridLength(3.5, GridUnitType.Star);
            content.RowDefinitions.Add(rowDef);
            rowDef        = new RowDefinition();
            rowDef.Height = new GridLength(1.5, GridUnitType.Star);
            content.RowDefinitions.Add(rowDef);
            rowDef        = new RowDefinition();
            rowDef.Height = new GridLength(0.5, GridUnitType.Star);
            content.RowDefinitions.Add(rowDef);
            rowDef        = new RowDefinition();
            rowDef.Height = new GridLength(0.5, GridUnitType.Star);
            content.RowDefinitions.Add(rowDef);
            rowDef        = new RowDefinition();
            rowDef.Height = new GridLength(0.5, GridUnitType.Star);
            content.RowDefinitions.Add(rowDef);

            // Add the ColumnDefinitions to the Grid which is a content to be printed
            ColumnDefinition colDef = new ColumnDefinition();

            colDef.Width = new GridLength(100, GridUnitType.Star);
            content.ColumnDefinitions.Add(colDef);


            // Create the "Windows 8 SDK Sample" header which consists of an image and text in a stack panel
            // and add it to the content grid
            //Image windowsLogo = new Image();
            //windowsLogo.Source = new BitmapImage(new Uri("ms-appx:///Assets/SmallLogo.png"));

            //TextBlock headerText = new TextBlock();
            //headerText.TextWrapping = TextWrapping.Wrap;
            //headerText.Text = "I Love Notes";
            //headerText.FontSize = 20;
            //headerText.Foreground = new SolidColorBrush(Colors.Black);

            //StackPanel sp = new StackPanel();
            //sp.Orientation = Orientation.Horizontal;
            //sp.Children.Add(windowsLogo);
            //sp.Children.Add(headerText);


            StackPanel outerPanel = new StackPanel();

            outerPanel.Orientation       = Orientation.Vertical;
            outerPanel.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Top;
            //outerPanel.Children.Add(sp);
            outerPanel.SetValue(Grid.RowProperty, 1);


            TextBlock sampleTitle = new TextBlock();

            sampleTitle.TextWrapping = TextWrapping.Wrap;
            sampleTitle.Text         = _noteForPrinting.NoteBook.Title;
            sampleTitle.FontSize     = 22;
            sampleTitle.FontWeight   = FontWeights.Bold;
            sampleTitle.Foreground   = new SolidColorBrush(Colors.Black);
            outerPanel.Children.Add(sampleTitle);

            content.Children.Add(outerPanel);


            // Create Microsoft image used to end each page and add it to the content grid
            Image microsoftLogo = new Image();

            microsoftLogo.Source = new BitmapImage(new Uri("ms-appx:///Assets/SmallLogo.png"));
            microsoftLogo.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left;
            microsoftLogo.SetValue(Grid.RowProperty, 6);
            content.Children.Add(microsoftLogo);


            // Add the copywrite notice and add it to the content grid
            TextBlock copyrightNotice = new TextBlock();

            copyrightNotice.Text         = "© 2012 Microsoft. All rights reserved.";
            copyrightNotice.FontSize     = 16;
            copyrightNotice.TextWrapping = TextWrapping.Wrap;
            copyrightNotice.Foreground   = new SolidColorBrush(Colors.Black);
            copyrightNotice.SetValue(Grid.RowProperty, 7);
            copyrightNotice.SetValue(Grid.ColumnSpanProperty, 2);
            content.Children.Add(copyrightNotice);


            // If lastRTBOAdded is null then we know we are creating the first page.
            bool isFirstPage = lastRTBOAdded == null;

            FrameworkElement      previousLTCOnPage = null;
            RichTextBlockOverflow rtbo = new RichTextBlockOverflow();

            // Create the linked containers and and add them to the content grid
            if (isFirstPage)
            {
                // The first linked container in a chain of linked containers is is always a RichTextBlock
                if (ShowText)
                {
                    RichTextBlock rtbl = new RichTextBlock();
                    rtbl.SetValue(Grid.RowProperty, 2);
                    rtbl = AddContentToRTBl(rtbl);
                    int a = rtbl.Blocks.Count();
                    rtbl.Foreground = new SolidColorBrush(Colors.Black);
                    content.Children.Add(rtbl);

                    // Save the RichTextBlock as the last linked container added to this page
                    previousLTCOnPage = rtbl;
                }

                if (ShowImage)
                {
                    if (_noteForPrinting.Images.Count > 0)
                    {
                        StackPanel imgList = new StackPanel();
                        if (ShowText)
                        {
                            imgList.Orientation = Orientation.Horizontal;
                        }
                        else
                        {
                            imgList.Orientation = Orientation.Vertical;
                        }

                        imgList.SetValue(Grid.RowProperty, 3);

                        for (var i = 0; i < _noteForPrinting.Images.Count; i++)
                        {
                            Image pic = new Image();
                            pic.Source = new BitmapImage(new Uri(_noteForPrinting.Images[i].ToBaseUrl()));
                            pic.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left;
                            pic.Margin = new Thickness(2);

                            if (ShowText)
                            {
                                pic.Width = pic.Height = 250;
                                imgList.Children.Add(pic);
                                //content.RowDefinitions[3].Height = new GridLength(2.5, GridUnitType.Star);
                            }
                            else
                            {
                                pic.Width = pic.Height = 350;
                                imgList.Children.Add(pic);
                                //page.Children.Add(pic);
                            }
                        }

                        if (ShowText)
                        {
                            content.Children.Add(imgList);
                        }
                        else
                        {
                            page.Children.Add(imgList);
                        }
                    }
                }

                if (ShowTags)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (var tag in _noteForPrinting.Tags)
                    {
                        sb.AppendFormat("[{0}] ", tag);
                    }

                    RichTextBlock rtbl = new RichTextBlock();
                    rtbl.SetValue(Grid.RowProperty, 5);

                    var run = new Run();
                    run.Text = sb.ToString();
                    Paragraph para = new Paragraph();
                    para.FontSize = 16;
                    para.Inlines.Add(run);

                    rtbl.Foreground = new SolidColorBrush(Colors.Black);
                    rtbl.Blocks.Add(para);

                    content.Children.Add(rtbl);
                }
            }
            else if (ShowText)
            {
                // This is not the first page so the first element on this page has to be a
                // RichTextBoxOverflow that links to the last RichTextBlockOverflow added to
                // the previous page.
                rtbo = new RichTextBlockOverflow();
                rtbo.SetValue(Grid.RowProperty, 2);
                content.Children.Add(rtbo);

                // Keep text flowing from the previous page to this page by setting the linked text container just
                // created (rtbo) as the OverflowContentTarget for the last linked text container from the previous page
                lastRTBOAdded.OverflowContentTarget = rtbo;

                // Save the RichTextBlockOverflow as the last linked container added to this page
                previousLTCOnPage = rtbo;
            }


            if (ShowText)
            {
                // Create the next linked text container for on this page.
                rtbo = new RichTextBlockOverflow();
                rtbo.SetValue(Grid.RowProperty, 3);

                // If this linked container is not on the first page make it span 2 columns.
                if (!isFirstPage || !ShowImage)
                {
                    // Add the RichTextBlockOverflow to the content to be printed.
                    content.Children.Add(rtbo);
                }

                // Add the new RichTextBlockOverflow to the chain of linked text containers. To do this we much check
                // to see if the previous container is a RichTextBlock or RichTextBlockOverflow.
                if (previousLTCOnPage is RichTextBlock)
                {
                    ((RichTextBlock)previousLTCOnPage).OverflowContentTarget = rtbo;
                }
                else
                {
                    ((RichTextBlockOverflow)previousLTCOnPage).OverflowContentTarget = rtbo;
                }

                // Save the last linked text container added to the chain
                previousLTCOnPage = rtbo;

                // Create the next linked text container for on this page.
                rtbo = new RichTextBlockOverflow();
                rtbo.SetValue(Grid.RowProperty, 4);
                content.Children.Add(rtbo);

                // Add the new RichTextBlockOverflow to the chain of linked text containers. We don't have to check
                // the type of the previous linked container this time because we know it's a RichTextBlockOverflow element
                ((RichTextBlockOverflow)previousLTCOnPage).OverflowContentTarget = rtbo;
            }
            // We are done creating the content for this page. Add it to the Canvas which represents the page
            page.Children.Add(content);

            // Add the newley created page to the printing root which is part of the visual tree and force it to go
            // through layout so that the linked containers correctly distribute the content inside them.
            //PrintingRoot.Children.Add(page);
            //PrintingRoot.InvalidateMeasure();
            //PrintingRoot.UpdateLayout();

            // Add the newley created page to the list of pages
            printPreviewPages.Add(page);

            // Return the last linked container added to the page
            return(rtbo);
        }