WPF - FlowDocument 的自动行号?
我刚刚开始为当前项目制定合同生成例程,要求之一是合同中的每一行都必须编号。编号应位于左边距,并用垂直线将编号与文档内容的其余部分分开。
我很确定我可以使用固定文档来解决这个要求,但这不会很有趣。无论如何,我可以用 FlowDocument 来做到这一点吗?
I'm just starting on a contract generation routine for my current project and one of the requirements is that each of the lines in the contract must be numbered. The number should be located in the left margin with a vertical rule separating the numbering from the rest of the document content.
I'm pretty sure I can tackle this requirement with a FixedDocument, but it won't be fun. Is there anyway I can do this with a FlowDocument instead?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用下面发布的我的 WpfPrint 帮助程序类轻松地使用固定文档来完成此操作。要将其用于 XPS 创建,只需使用 XPS 的构造函数:
您现在可以循环并添加您想要的任何内容; TextBlocks 很可能就是您所寻找的:
如果您将它们创建为包装的,它们将自行包装;每个项目在添加时都会被测量。如果它不适合页面,辅助类会添加一个新页面并将其流到新页面上,这样您就可以从 FlowDocument 中获得所需的内容。您可以随时更改 CurX 和 CurY,以在放置项目时跳过水平或垂直空间。完成后,您可以像这样打印到打印机:
或者您可以另存为 XPS 文件:
这是帮助程序类。享受!您将永远不想再使用 FlowDocument :-)
You can do this with a FixedDocument quite easily with my WpfPrint helper class, posted below. To use it for XPS creation just use the constructor for XPS:
You can now loop through and add whatever you want; TextBlocks would most likely be what you were looking for:
They'll wrap themselves if you create them wrapped; each item, as it is added, is measured. If it doesn't fit on the page, the helper class adds a new page and flows it onto the new page, so you get what you wanted from FlowDocument. You can change CurX and CurY at any time to skip horizontal or vertical space when placing items. When you are done, you can print to a printer like this:
Or you can save as an XPS file:
Here is the helper class. Enjoy! You'll never want to use a FlowDocument again :-)