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

THX

有帮助吗?

解决方案

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

WPF将在Document中写入您提供的元素。这意味着它不会以任何方式缩放以适合页面内容。

假设您的文档大小正确(假设字母),您需要确定文档的可打印区域,并在将其写入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所需的数量

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top