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(); }
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); }
private static 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; PageLoadState pageState = new PageLoadState(page, printPreviewPages.Count); pageState.ReadyAction = async(pageNumber, currentPage) => { // Ignore if this is not the current page if (Interlocked.CompareExchange(ref currentPreviewPage, currentPreviewPage, pageNumber) == pageNumber) { await Window.Current.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { //await new Windows.UI.Popups.MessageDialog("Content loaded").ShowAsync(); printDocument.SetPreviewPage(pageNumber + 1, currentPage); }); } }; // 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(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); // 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 RichTextBlock rtbl = new RichTextBlock(); rtbl.SetValue(Grid.RowProperty, 0); rtbl = AddContentToRTBl(rtbl); int a = rtbl.Blocks.Count(); rtbl.Foreground = new SolidColorBrush(Windows.UI.Colors.Black); content.Children.Add(rtbl); // Save the RichTextBlock as the last linked container added to this page previousLTCOnPage = rtbl; } else { // 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, 0); 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, 1); // 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, 2); 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(pageState); // Return the last linked container added to the page return(rtbo); }
public static void SetItemsSource(RichTextBlock obj, IEnumerable <object> value) { obj.SetValue(ItemsSourceProperty, value); }
public static void SetBodyIndent(RichTextBlock obj, double value) { obj.SetValue(BodyIndentProperty, value); }
public static void SetBodyFontSize(RichTextBlock obj, double value) { obj.SetValue(BodyFontSizeProperty, value); }