How do I print a TextFile OR contents of a TextBox in Metro apps?

此生再无相见时 提交于 2020-01-02 17:54:49

问题


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:


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



来源:https://stackoverflow.com/questions/15595706/how-do-i-print-a-textfile-or-contents-of-a-textbox-in-metro-apps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!