问题
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