How do I print a TextFile OR contents of a TextBox

2019-05-21 05:41发布

I have a TextBox control in my Metro app and need to be able to simply print its contents. I have done my research ever since Windows 8 Dev Preview was around and I still cannot figure it out.

I've tried samples, read other answers and read the documentation - over, and over, and over. It just doesn't seem possible. So, after what, 2 years? I'm offering all my reputation (well, as much as they'll allow) in the hopes that someone can help me.

1条回答
Ridiculous、
2楼-- · 2019-05-21 06:25

Here I have created a simple helper class which help you to print the Textbox content with its formatting. You just need to call static method of class Printer. The project on GitHub also contain test app.

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.)

You can add helper class via NuGet. If you want to enhance my existing helper class, fork on GitHub

查看更多
登录 后发表回答