views:

34

answers:

2

Hello,

Trying to implement a simple print in SL4. I have a DataGrid that I would like to print out, but thus far whatever I try to print out comes out as a blank page in the printer. It also seems to take about 30-60 seconds to actually print out (but that could be an unrelated issue).

My code is fairly straightforward:

private void MenuPrint_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            PrintDocument document = new PrintDocument();
            document.PrintPage += (s, args) =>
                {
                    args.PageVisual = this.MainDataGrid;
                    // args.PageVisual = this.LayoutRoot;
                };

            // Print
            document.Print("Test Print Job");
        }

I've even wondered if it is because the items are too large?

The XAML for the MainDataGrid control is fairly straight-forward as well:

<sdk:DataGrid Grid.Row="3" AutoGenerateColumns="True" Name="MainDataGrid" FontSize="10" Visibility="Visible" />
A: 

the only difference I can see between your example and the MSDN one is that you're using an anonymous method for the PrintPage event handler. Have you tried to handle the EndPrint event to check for errors?

vlad
I took a look at the EndPrint function, and the args.Error items appears to be null. My application seems to lock up / freeze for about 60 seconds while it is trying to print, and it sends an item to the printer (it says spooling in the print monitor), and then it actually prints out a blank page.
enforge
I also have the following if I try to debug soem of the properties of the assigned args:args.PrintableArea.IsEmpty: Falseargs.PrintableArea.Height: 1024args.PrintableArea.Width: 784args.PageVisual.Visibility: VisibleThe application freezing for 60 seconds while it tries to print (I would think this async call would truly be async?) is concerning as well.
enforge
A: 

Turns out this was PC-related and not a code issue after all. For whatever reason, the same code started working today (after a machine reboot).

The one thing that is still a problem is that the Silverlight interface does seem to hang for about 30-60 seconds while the printing is happening, but it eventually does release and print./

enforge
Thread your print job?
stocherilac
I suppose I can. Just not sure why my print job takes 30-60 seconds, when anything else I print from this PC takes about 1 second. I am not doing anything fancy, simply calling the PrintDocument.Print method.
enforge