将 WPF (XAML) 控件转换为 XPS 文档
我可以使用现有的 WPF (XAML) 控件,对其进行数据绑定并将其转换为可以使用 WPF XPS 文档查看器显示和打印的 XPS 文档吗? 如果是这样,怎么办? 如果没有,我应该如何使用 XPS/PDF/等在 WPF 中进行“报告”?
基本上,我想采用现有的 WPF 控件,对其进行数据绑定以将有用的数据放入其中,然后使其可供最终用户打印和保存。 理想情况下,文档创建将在内存中完成,除非用户专门保存文档,否则不会访问磁盘。 这可行吗?
Can I take an Existing WPF (XAML) Control, databind it and turn it into an XPS document that can be displayed and printed using the WPF XPS Document Viewer?
If so, how?
If not, how should I be doing ‘reporting’ in WPF using XPS/PDF/etc?
Basically I want to take an existing WPF control, databind it to get useful data into it and then make it printable and saveable for the end user. Ideally the document creation would be done in memory and wouldn’t hit the disk unless the user specifically saved the document. Is this feasible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,在弄乱了一堆不同的样本之后,所有这些样本都非常复杂,需要使用文档编写器、容器、打印队列和打印票证,我发现了 Eric Sinks 的文章 在 WPF 中打印
简化的代码只有 10 行长,
我的示例相当简单,它不包括页面大小调整和方向,其中包含一组完全不同的问题,这些问题无法按您的预期工作。
它也不包含任何保存功能,因为 MS 似乎忘记在文档查看器中包含“保存”按钮。
保存功能相对简单(也来自 Eric Sinks 的文章),
所以答案是肯定的,您可以采用现有的 WPF (XAML) 控件,对其进行数据绑定并将其转换为 XPS 文档 - 这并不那么困难。
Actually after messing around with heaps of different samples, all of which are incredibly convoluted and require the use of Document Writers, Containers, Print Queues and Print Tickets, I found Eric Sinks article about Printing in WPF
The simplified code is a mere 10 lines long
My sample is fairly simplistic, it doesn't include Page Sizing and Orientation which contains a whole different set of issues that don't work as you would expect.
Nor does it contain any save functionality as MS seem to have forgotten to include a Save button with the Document Viewer.
Save Functionality is relatively simple (and is also from Eric Sinks article)
So the answer is Yes, you can take an Existing WPF (XAML) Control, databind it and turn it into an XPS document - and its not all that difficult.