views:

492

answers:

1

Hi all,

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

A: 

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

Kiranu
Thanks for your solution Kiranu :)
Fatih Şenel