views:

25

answers:

0

Hi,

I am trying to print a wpf document. I am using documentpaginator for pagination and a user control to create actual visual to print. My user control has few textboxes and a datagrid binded to data objects which are passed to the user control at runtime.

Now the code works great when printing to an XPS document but when it prints to a physical printer, my datagrid is printed empty though other textboxes are printing perfectly.

Below is the code for paginator class GetPage Method :

  SaleOrderPage page = new SaleOrderPage(order, pageNumber, controlSize);
        page.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
        page.Arrange(new Rect(new Point(0, 0), PageSize));
        page.InitPrint();
        page.UpdateLayout();

        return new DocumentPage(page);

InitPrint method is initializing my datagrid and binding it to the datasource. Here is the code for InitPrint method.

 public void InitPrint() {
        var sales = ctx.SalesOrders.Where(so => so.Id.Equals(order.Id)).First().Sales.Skip(pageNumber * PageRows).Take(PageRows);
        var printData = sales.Select(x => new {
            Particulars = string.Format("{0} - {1}", x.Item.Brand.Name, x.Item.Shade.Name),
            Quantity = string.Format("{0} {1}", x.Quantity, x.Item.Brand.Unit.Symbol)
        }).ToList();

        dgSales.ItemsSource = printData;
        dgSalesCopy.ItemsSource = printData;
    }

I believe I am missing some step when printing to actual printer because it works as expected to an XPS printer but not to a physical printer.

Thanks for reading question,

Naveen