Why does silverlight run into an endless loop when printing document longer than 1 page? .HasMorePages = true

故事扮演 提交于 2019-12-11 06:38:54

问题


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:


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.



来源:https://stackoverflow.com/questions/3677558/why-does-silverlight-run-into-an-endless-loop-when-printing-document-longer-than

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!