Why does silverlight run into an endless loop when printing document longer than 1 page? .HasMorePages = true
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.HasMo开发者_运维百科rePages = 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.
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.
精彩评论