WPF 工具包数据网格

发布于 2024-07-14 21:22:03 字数 161 浏览 4 评论 0原文

我想在 XPS 文档中显示数据网格内容(行、列)。我有 20 列。 当我使用 XPSDocumentWriter.Write 方法将 datagrid 发送到 XPS 时,它只显示一些列而不是全部。我如何在 xps 中显示所有列和行(如 Xceed datagrid xps 导出)

谢谢

I want to show datagrid content (rows,columns) in XPS document.I have 20 columns. When i sent datagrid to XPS with XPSDocumentWriter.Write method ,it just show some columns not all of them.How can i show all columns and rows in xps(like Xceed datagrid xps exporting)

Thx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

放我走吧 2024-07-21 21:22:03

问题可能在于网格宽度与 XPSDocumentWriter 页面大小的关系。

WPF 将按原样将您提供的元素写入文档中。 这意味着它不会以任何方式缩放以适应页面的内容。

假设您的文档大小正确(假设是字母),您需要确定文档的可打印区域,并在将其写入 XPSDocumentWriter 之前将 RenderTransform 应用于网格。

执行此操作的代码如下所示:

Grid grd = new Grid();
XpsDocumentWriter wrt = new XpsDocumentWriter();
//Bunch of code to manipulate your grid here

//Now we calculate the scaling required:
double ScaleX = PageWidth / grd.Width; //The page width must be in Device Independent Units
double ScaleY = ScaleX;

grd.RenderTransform = new ScaleTransform(ScaleX, ScaleY);

wrt.Write(grd);

编辑:更改了代码,以便 ScaleX 和 ScaleY 都指向使网格完全适合 XpsDocument 所需的量

The problem is probably with the width of your grid in relation of the XPSDocumentWriter's pagesize.

WPF will write in the Document the element you provide as is. That means that it will not be scaled in any way to fit the content of the page.

Assuming your document is the correct size (lets suppose letter), you need to determine the printable area of the document and apply a RenderTransform to the grid before you write it into the XPSDocumentWriter

The code to do it would be something like:

Grid grd = new Grid();
XpsDocumentWriter wrt = new XpsDocumentWriter();
//Bunch of code to manipulate your grid here

//Now we calculate the scaling required:
double ScaleX = PageWidth / grd.Width; //The page width must be in Device Independent Units
double ScaleY = ScaleX;

grd.RenderTransform = new ScaleTransform(ScaleX, ScaleY);

wrt.Write(grd);

EDIT: Changed the code so that both the ScaleX, and ScaleY point to the amount required to make the grid fit completely in the XpsDocument

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文