通过 Wpf 控件打印文档并转换为 XPS
我正在尝试将 XAML 控件转换为 XPS 文档,但我想以批处理模式执行此操作 - 在内存中渲染控件并将其打印到 XPS,而不将其渲染在屏幕上。即使没有 GUI,该项目也应该可以工作。
我已阅读有关 stackoverflow 的相关主题,但它无法正常工作。我可以创建控件,设置 DataContext,但输出 xps 为空。如果我在屏幕上渲染控件然后打印它,一切都可以,但是如果我想在批处理模式下执行此操作,我会得到空文档(只有静态标签等)。
我如何强制控件绑定控件有数据吗?
下一个困难的部分是:如果我打印长多页控件,如何在每个页面上添加自定义页眉? (例如列表?)
I'm trying to convert XAML control to XPS document, but i'd like to do this in batch mode - render control in memory and print it to XPS without rendering it on the screen. This project should work even without GUI.
I've read Related topic on stackoverflow, but it's not working properly. I can create control, set DataContext, but output xps is empty. If i render control on the screen and then print it, everything is ok, but if i'd like to do this in batch mode, i got empty document (there was only static labels etc.)
How can i force control to bind controls with data?
Next hard part would be: how can i add my custom header on each page if i print long-multi-page control? (ex. list?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我跳过你的第二个问题,因为它足够复杂,可以独立存在。
我遇到了同样的问题,但可能是由几个不同的原因引起的。
如果问题是因为绑定尚未“触发”,则该解决方案有点棘手,但如果您控制 DataContext 类型,则很容易做到。您只需向您的类型添加一个公共或内部方法,即可为每个公共属性触发 PropertyChanged 事件。这是一个示例:
然后,您可以这样使用它:
如果这不起作用,您可能会遇到一个错误,即第一页上的绑定永远不会显示。在重新找到解决方案之前,我必须挖掘一段时间。
I'm skipping your second question as it is complex enough to be a standalone.
I faced the same issue, but it may be caused by a couple of different things.
If the issue is because the bindings haven't been "tripped" yet, the solution is slightly hacky but is easy to do if you control the DataContext type. You just add a public or internal method to your type that allows you to fire off PropertyChanged events for each public property. Here's an example:
then, you can use it thusly:
If that isn't working, you might be encountering a bug where the bindings on the first page never show up. I'd have to dig for awhile before I can re-find the solution to that.