Hello,
Please find below the code to print with C#/XAML for HTML5.
Just create a new class named "PrintHelper" in your project, and replace the class code with the following one:
Code: Select all
using System;
using System.Windows;
using Windows.UI.Xaml;
public static class PrintHelper
{
    public static void Print(UIElement uiElement)
    {
        if (CSharpXamlForHtml5.DomManagement.IsControlInVisualTree(uiElement))
        {
            if (CSharpXamlForHtml5.Environment.IsRunningInJavaScript)
            {
                JSIL.Verbatim.Expression(@"
                    var printPreview = window.open('about:blank', 'print_preview', 'resizable=yes,scrollbars=yes,status=yes');
                    var printDocument = printPreview.document;
                    printDocument.open();
                    printDocument.write('<!DOCTYPE html>'+
                    '<html>'+
                        $0.innerHTML+
                    '</html>');
                    printDocument.close();
                    printPreview.print();", CSharpXamlForHtml5.DomManagement.GetDomElementFromControl(uiElement));
            }
            else
            {
                MessageBox.Show("Printing is not available when running inside the Simulator.");
            }
        }
        else
            throw new Exception("You can only print a UIElement that is in the visual tree. To fix the issue, add the UIElement to the visual tree before printing it.");
    }
}
To use the class, just call the "PrintHelper.Print(uielement)" method, passing the UIElement that you want to print.
Regards,
The C#/XAML for HTML5 team