Telerik blogs

In Silverlight 4 you can use PrintDocument to print easily any UIElement:

   var doc = new PrintDocument();
   doc.DocumentName = YourDocumentName;

   doc.PrintPage += (s, e) =>
   {
        e.PageVisual = YouUIElement;
   };
   doc.Print();


and I’ve made an extension method that can be used to print any UIElement on multiple pages:

public static void Print(this UIElement source, string documentName)
{
    var doc = new PrintDocument();
    doc.DocumentName = documentName;

    var offsetY = 0d;
    var totalHeight = 0d;

    var canvas = new Canvas();
    canvas.Children.Add(source);

    doc.PrintPage += (s, e) =>
    {
        e.PageVisual = canvas;

        if (totalHeight == 0)
        {
            totalHeight = source.DesiredSize.Height;
        }

        Canvas.SetTop(source, -offsetY);

        offsetY += e.PrintableArea.Height;

        e.HasMorePages = offsetY <= totalHeight;
    };

    doc.Print();
}

You can download the attached application (Visual Studio 2010) to check how easily you can print RadGridView for Silverlight on multiple pages.

Enjoy!


About the Author

Vladimir Enchev

is Director of Engineering, Native Mobile UI & Frameworks

Related Posts

Comments

Comments are disabled in preview mode.