1
votes

I'm currently developing an UWP app and using the Windows.Graphics.Printing.PrintManager class to show the preview window. I have some controls which affect the result and I call printDocument.InvalidatePreview() to refresh the preview when user changes them. It works fine until user resizes the window. After that the preview will not be updated after calling printDocument.InvalidatePreview().

It’s absolutely unclear what’s going on within InvalidatePreview, because the documentation is very poor and there’s no source code.

Does anyone know a fix or a workaround for that?

1

1 Answers

0
votes

I wrote a very simple demo to try to reproduce your issue but I cannot reproduce. I invoke the printDoc.InvalidatePreview() after the user change the print preview option, code as follows

  if (optionId == "PageContent")
  {
      await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
      {
          printDoc.InvalidatePreview();
      });
  }

And it worked well, it also worked after the app's window resized. It seems the InvaliddatePreview() will recall PrintDocument.GetPreviewPage event if you have subscribed it and the print preview will refresh. I uploaded the demo to github, you can download for testing and compare with your project to find differences. If it cannot resolved by compare differences, you can try to reproduce your issue on this demo and let us help solve again.

More details please reference:https://msdn.microsoft.com/en-us/windows/uwp/devices-sensors/print-from-your-app. And the official sample:https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/Printing