locked
how i used Quickstart: Printing from your app (XAML)

    Question

  • hi

    i found this page about printing your app and download PrintSample.

    http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh465204.aspx

    for learning printing in my app.

    but i dont know how used this code.

    for example where add this code in my page:

    protected virtual void RegisterForPrinting()
    {
        // Create the PrintDocument.
        printDocument = new PrintDocument();
    
        // Save the DocumentSource.
        printDocumentSource = printDocument.DocumentSource;
    
        // Add an event handler which creates preview pages.
        printDocument.Paginate += CreatePrintPreviewPages;
    
        // Add an event handler which provides a specified preview page.
        printDocument.GetPreviewPage += GetPrintPreviewPage;
    
        // Add an event handler which provides all final print pages.
        printDocument.AddPages += AddPrintPages;
    
        // Create a PrintManager and add a handler for printing initialization.
        PrintManager printMan = PrintManager.GetForCurrentView();
        printMan.PrintTaskRequested += PrintTaskRequested;
    
        // Initialize print content for this scenario
        PreparePrintContent();
    }
    

    when i add this code to my app page appear very error in error window.

    i add using Windows.UI.Xaml.Printing; and using Windows.Graphics.Printing; in my app page.

    but error appear .

    how can used this code in my code.

    i want printing my list view that is in my page (listview name is TABLE)

    tank you


    Amir Ameri

    Wednesday, December 10, 2014 8:41 AM

Answers

  • Hi Amir,

    The code sample shows you how to print XAML. I think you are miss the definition of BasePrintPage class. That project define printDocumentSource and other classes in BasePrintPage. You need to inherit this BasePrintPage class in your MainPage class.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    • Marked as answer by AMIR ameri Friday, December 19, 2014 5:25 AM
    Friday, December 19, 2014 2:17 AM
    Moderator
  • The reality is printing in metro app is needlessly complicated. In a wpf project, if you want to print a simple string like "hello world", it took 4 lines of code. In metro, to print out the some string, it requires 100+ lines of code. Just printing nicely formatted documents alone took me 3 months to get it right.

    MS did not need to make printing so extraordinarily difficult.

    • Marked as answer by AMIR ameri Monday, December 22, 2014 11:53 AM
    Friday, December 19, 2014 5:42 AM

All replies

  • Hi Amir,

    As I know, this approach need PreparePrintContent and RegisterForPrinting. I assume you have added this two in your project. Note that the mainpage must inherit from BasePrintPage class. Please check the following code snippet in your project.

      public sealed partial class ScenarioInput1 : BasePrintPage

    You can find these code snippet form the sample. https://code.msdn.microsoft.com/windowsapps/Print-Sample-c544cce6.

    Please feel free to let me know if you have any concerns.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Thursday, December 11, 2014 7:44 AM
    Moderator
  • when i added PreparePrintContent and RegisterForPrinting appear very error:


    Amir Ameri


    • Edited by AMIR ameri Thursday, December 11, 2014 9:11 AM
    Thursday, December 11, 2014 8:35 AM
  • no simple way to print my list view?

    its very complicated

    :(


    Amir Ameri

    Thursday, December 11, 2014 10:18 AM
  • Hi Amir,

    The code sample shows you how to print XAML. I think you are miss the definition of BasePrintPage class. That project define printDocumentSource and other classes in BasePrintPage. You need to inherit this BasePrintPage class in your MainPage class.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    • Marked as answer by AMIR ameri Friday, December 19, 2014 5:25 AM
    Friday, December 19, 2014 2:17 AM
    Moderator
  • The reality is printing in metro app is needlessly complicated. In a wpf project, if you want to print a simple string like "hello world", it took 4 lines of code. In metro, to print out the some string, it requires 100+ lines of code. Just printing nicely formatted documents alone took me 3 months to get it right.

    MS did not need to make printing so extraordinarily difficult.

    • Marked as answer by AMIR ameri Monday, December 22, 2014 11:53 AM
    Friday, December 19, 2014 5:42 AM
  • its very difficult.

    i save my list view in a file.txt then user can print that file.out of my app!!

    i cant print directly from my app :(


    Amir Ameri

    Monday, December 22, 2014 11:58 AM