views:

57

answers:

1

Hi. My 1st question here on stackoverflow. I am trying to print a long grid, which was dynamically generated.

pdoc.PrintPage += (p, args) =>
        {
            args.PageVisual = myGrid;
            args.HasMorePages = false;
        };

When I use args.HasMorePages = false;, it prints the first page of the grid as it should (although it takes some time, since it sends a 123MB big bitmap to the poor printer - thanks for silverlight 4's print feature implementation.).

However, when I enable printing more pages withargs.HasMorePages = true;, the printing job runs amok on the memory and sends endless copies of the first printing page of the document - effectively disabling my developer machine. Even if the grid is only 2 pages long.

Why does this happen? What is a possible workaround here? All I found on the net is that SL handles printing badly, but not a real solution.

+1  A: 

The HasMorePages property indicates to silverlight printing that you have a least one more page to print. The PrintPage page event fires for each page to be printed.

Hence when you set HasMorePages to true you will get another PrintPage event, if you always set it true (as your code appears to be doing) you are creating an infinite loop.

At some point the code has to leave HasMorePages set to false.

Ultimately its up to you the developer to perform all the pagination logic and decide what appears on each page, Silverlight does not automagically do that for you.

AnthonyWJones
Yes I realized that. Following this guide (http://www.silverlightshow.net/items/Advanced-printing-in-Silverlight-4.aspx) gives a practical example, that I now customized for my own needs. Problem solved (for now).
gabore