I am also struggling with this. I switched to an example SDK. This solution may be useful to you. If there is a way that you can put what you want to print in a RichTextBox, you can create paragraphs for it programmatically. And replace the RichTextBox in the SDK example with an empty StackPanel to which you specified the grid requirements, and this will solve your problem. My problem was not exactly the same problem, because I did this with the creation of 2 column lists of products. The trick was using a CourierNew fixed-width font in my example.
On your page that invokes print libraries, you must have this in XAML
<Canvas x:Name="PrintCanvas" Opacity="0"/>
On the page replacing the PageToPrint page, you can build this material directly in the designer. I pass the collection to a page instance and then compute the layout directly in the PageToPrint lookup, like this ,,
private void MakeThePrintOut() { RichTextBlock gutOne = initBlock(); PopulateBlock(gutOne); ContentStack.Children.Add(gutOne); } private RichTextBlock initBlock() { RichTextBlock gutInitBlock = new RichTextBlock(); gutInitBlock.Foreground = new SolidColorBrush(Windows.UI.Colors.Black); gutInitBlock.FontSize = 18; gutInitBlock.OverflowContentTarget = FirstLinkedContainer; gutInitBlock.FontFamily = new FontFamily("Courier New"); gutInitBlock.VerticalAlignment = VerticalAlignment.Top; gutInitBlock.HorizontalAlignment = HorizontalAlignment.Left; return gutInitBlock; } private void PopulateBlock( RichTextBlock Blocker) { bool firstItem = true; int firstLength = 0; Paragraph paraItem = null; Run itemRun = null; string CurrentIsle = "None"; foreach( Grocery j in Grocs) { if (j.Isle != CurrentIsle) { if ((CurrentIsle != "None") && (!firstItem)) { paraItem.Inlines.Add(itemRun); Blocker.Blocks.Add(paraItem); } CurrentIsle = j.Isle; firstItem = true; Paragraph paraIsle = new Paragraph(); Run paraRan = new Run(); paraRan.Text = " " + j.Isle; paraIsle.Inlines.Add(paraRan); Blocker.Blocks.Add(paraIsle); } if (firstItem) { paraItem = new Paragraph(); itemRun = new Run(); itemRun.Text = " [] " + j.Item; firstLength = j.Item.Length; firstItem = false; } else { firstItem = true; string s = new string(' ', 30 - firstLength); itemRun.Text += s + "[] " + j.Item; paraItem.Inlines.Add(itemRun); Blocker.Blocks.Add(paraItem); } } if (!firstItem) { paraItem.Inlines.Add(itemRun); Blocker.Blocks.Add(paraItem); } }
This is not exactly what you are looking for, but I know how difficult it is to find something that makes sense to answer the question about printing. If you want to see the full example, my GitHub.com/Gibbloggen GutenbergOne project was my prototype that I developed for this. And I also imported EssentialGrocer into my main project, this is also open source in the same place. This, only today, includes printing a shopping list.
Hope some of this helps, I really struggled with this.
source share