Microsoft's documentation & sample for printing is too complex. The sample app for printing shows only how to print RichTextBlock. There's no tutorial to print the TextBox content in a Windows Store app. Moreover, to print a single line string, one has to write too much code rather than a maximum of 10 lines in WinForm. So, this helper class provides the simplest method to print the text box content. It has only one static method. It prints the text box content with its formatting. It's majorly based on MSDN print sample.
I got the idea to write a library from the following Stack Overflow questions:
How to use it ?
You have to call just one static method ShowPrintUIAsync of class Printer, it will do print job on your behalf.
await Printer.ShowPrintUIAsync(PrintPreview, MyTextBox, Guid.NewGuid().ToString());
- PrintPreview is a canvas, which is mandatory to show print preview in device charm. You have to declare in your XAML.
- MyTextBox is a text box object, whose text content is going to be printed.
- Guid.NewGuid().ToString() is a file name for printing the document. (It will be applied if you are creating PDF or XPS file via printing.)
I would be glad to have issues or suggestions from you, so I can improve this. If you want to fork the repository or post issues, find this helper class on GitHub .