Silverlight printing busy\progress bar

喜夏-厌秋 提交于 2019-12-24 15:48:20

问题


I'm using Silverlight 4 to print but I would like some sort of progress bar or busy indicator.

I've tried to using a progress bar but it is not really working. The 2 issues I have are:

  • the progress bar does not indicate progress, I have IsIndeterminate=True, but it does not animate when printing starts (Print dialog's Print button is clicked)
  • the progress bar visibility is not being set at the proper time, depending upon where I put the code to set visibility it displays either too soon (before print is clicked) or too late (after printing has worked for awhile)

I'm guessing, but I think the reason for the above is because when the print dialog is displayed Silverlight has handed off control to the OS for prining(??).

I tried using a dispatcher invoke but I get a security exception (dialog can only be displayed from user click).

Any ideas on how to deal with either of the above issues?

thanks.


回答1:


Create a BusyIndicator in your XAML, it's a part of the Silverlight Toolkit. And then during the BeginPrint event set the BusyIndicator's IsBusy to True. Also during EndPrint set IsBusy back to false.

  var docToPrint = new PrintDocument();

        docToPrint.BeginPrint += (s, args) =>
            {
                MyBusyIndicator.IsBusy = true;
                MyBusyIndicator.BusyContent = "Printing...";
            };

        docToPrint.PrintPage += (s, args) =>
            {
             args.PageVisual = this.MainCanvas;                      
            };

        docToPrint.EndPrint += (s, args) =>
            {
                MyBusyIndicator.IsBusy = false;
                MyBusyIndicator.BusyContent = "";
            };


来源:https://stackoverflow.com/questions/3843499/silverlight-printing-busy-progress-bar

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