Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is my Windows Store app not showing anything in the print preview?
    primarykey
    data
    text
    <p>I was using the <a href="http://code.msdn.microsoft.com/windowsapps/Print-Sample-c544cce6" rel="nofollow">PrintSample</a> and successfully modified the BasePrintPage code to the following (just trying to cut it down to a manageable size and the simplest case for testing):</p> <pre><code> protected PrintDocument printDocument = null; protected IPrintDocumentSource printDocumentSource = null; internal List&lt;UIElement&gt; printPreviewElements = new List&lt;UIElement&gt;(); protected event EventHandler pagesCreated; protected void PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs e) { PrintTask printTask = null; printTask = e.Request.CreatePrintTask("C# Printing SDK Sample", sourceRequested =&gt; { printTask.Completed += async (s, args) =&gt; { if (args.Completion == PrintTaskCompletion.Failed) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =&gt; { MessageDialog dialog = new MessageDialog("Something went wrong while trying to print. Please try again."); await dialog.ShowAsync(); }); } }; sourceRequested.SetSource(printDocumentSource); }); } protected void RegisterForPrinting() { printDocument = new PrintDocument(); printDocumentSource = printDocument.DocumentSource; printDocument.Paginate += CreatePrintPreviewPages; printDocument.GetPreviewPage += GetPrintPreviewPage; printDocument.AddPages += AddPrintPages; PrintManager printMan = PrintManager.GetForCurrentView(); printMan.PrintTaskRequested += PrintTaskRequested; } protected void UnregisterForPrinting() { if (printDocument != null) { printDocument.Paginate -= CreatePrintPreviewPages; printDocument.GetPreviewPage -= GetPrintPreviewPage; printDocument.AddPages -= AddPrintPages; PrintManager printMan = PrintManager.GetForCurrentView(); printMan.PrintTaskRequested -= PrintTaskRequested; } } protected void CreatePrintPreviewPages(object sender, PaginateEventArgs e) { printPreviewElements.Clear(); PrintTaskOptions printingOptions = ((PrintTaskOptions)e.PrintTaskOptions); PrintPageDescription pageDescription = printingOptions.GetPageDescription(0); AddOnePrintPreviewPage(pageDescription); if (pagesCreated != null) { pagesCreated.Invoke(printPreviewElements, null); } ((PrintDocument)sender).SetPreviewPageCount(printPreviewElements.Count, PreviewPageCountType.Intermediate); } protected void GetPrintPreviewPage(object sender, GetPreviewPageEventArgs e) { ((PrintDocument)sender).SetPreviewPage(e.PageNumber, printPreviewElements[e.PageNumber - 1]); } protected void AddPrintPages(object sender, AddPagesEventArgs e) { foreach (UIElement element in printPreviewElements) { printDocument.AddPage(element); } ((PrintDocument)sender).AddPagesComplete(); } protected void AddOnePrintPreviewPage(PrintPageDescription printPageDescription) { TextBlock block = new TextBlock(); block.Text = "This is an example."; block.Width = printPageDescription.PageSize.Width; block.Height = printPageDescription.PageSize.Height; printPreviewElements.Add(block); } protected override void OnNavigatedTo(NavigationEventArgs e) { RegisterForPrinting(); } protected override void OnNavigatedFrom(NavigationEventArgs e) { UnregisterForPrinting(); } </code></pre> <p>This works fine and dandy in the PrintSample, displaying a print preview page with the TextBox's text, "This is an example." But, when I throw this code into my own app, trying to invoke printing from a button displays a blank page. So what am I missing here? What is the PrintSample doing that I forgot to do?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload